Skip to content

Prettification issue with INTERFACE and pre-processor directive #3071

@RMeli

Description

@RMeli

If #if defined follows immediately after END INTERFACE, make pretty removes part of the interface.

diff --git a/pt-2.F b/pt-2.F
index a3a6a473a..fbd2d812b 100644
--- a/pt-2.F
+++ b/pt-2.F
@@ -17,15 +17,14 @@ MODULE cp_dlaf_utils
 
 CONTAINS
 
+! **************************************************************************************************
+!> \brief ...
+! **************************************************************************************************
    SUBROUTINE cp_dlaf_initialize()
-      INTERFACE
-         SUBROUTINE dlaf_init_aux() &
-            BIND(C, name='dlaf_init')
-         END SUBROUTINE dlaf_init_aux
       END INTERFACE
 
 #if defined(__DLAF)
       CALL dlaf_init_aux()
 #endif
-   END SUBROUTINE cp_dlaf_initialize
-END MODULE cp_dlaf_utils
+      END SUBROUTINE cp_dlaf_initialize
+   END MODULE cp_dlaf_utils

The following code snippet allows to reproduce the issue (placed on the root directory of the git repository):

!--------------------------------------------------------------------------------------------------!
!   CP2K: A general program to perform molecular dynamics simulations                              !
!   Copyright 2000-2023 CP2K developers group <https://cp2k.org>                                   !
!                                                                                                  !
!   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
!--------------------------------------------------------------------------------------------------!

MODULE cp_dlaf_utils
#include "src/base/base_uses.f90"
   IMPLICIT NONE

   PRIVATE

   CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_dlaf_utils'

   PUBLIC:: cp_dlaf_initialize

CONTAINS

   SUBROUTINE cp_dlaf_initialize()
      INTERFACE
         SUBROUTINE dlaf_init_aux() &
            BIND(C, name='dlaf_init')
         END SUBROUTINE dlaf_init_aux
      END INTERFACE

#if defined(__DLAF)
      CALL dlaf_init_aux()
#endif
   END SUBROUTINE cp_dlaf_initialize
END MODULE cp_dlaf_utils

Adding code between END INTERFACE and #if defined doesn't seem to cause issues:

!--------------------------------------------------------------------------------------------------!
!   CP2K: A general program to perform molecular dynamics simulations                              !
!   Copyright 2000-2023 CP2K developers group <https://cp2k.org>                                   !
!                                                                                                  !
!   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
!--------------------------------------------------------------------------------------------------!

MODULE cp_dlaf_utils
#include "src/base/base_uses.f90"
   IMPLICIT NONE

   PRIVATE

   CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_dlaf_utils'

   PUBLIC:: cp_dlaf_initialize

CONTAINS

   SUBROUTINE cp_dlaf_initialize()
      INTERFACE
         SUBROUTINE dlaf_init_aux() &
            BIND(C, name='dlaf_init')
         END SUBROUTINE dlaf_init_aux
      END INTERFACE

      CALL something()

#if defined(__DLAF)
      CALL dlaf_init_aux()
#endif
   END SUBROUTINE cp_dlaf_initialize
END MODULE cp_dlaf_utils

fprettify --diff FILES does not have any issue with either file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions