From 5f56a46c49207f3453bf8671f79fa8490ea99bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 29 Jun 2021 10:38:50 -0600 Subject: [PATCH 1/4] Model: add implicit_none (default false) --- src/fpm.f90 | 1 + src/fpm/manifest.f90 | 2 ++ src/fpm/manifest/package.f90 | 2 ++ src/fpm_model.f90 | 13 ++++++++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index c6703782bb..7d12bbe716 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -49,6 +49,7 @@ subroutine build_model(model, settings, package, error) type(string_t) :: include_dir model%package_name = package%name + model%implicit_none = package%implicit_none allocate(model%include_dirs(0)) allocate(model%link_libraries(0)) diff --git a/src/fpm/manifest.f90 b/src/fpm/manifest.f90 index 8c39aa6915..11409960be 100644 --- a/src/fpm/manifest.f90 +++ b/src/fpm/manifest.f90 @@ -178,6 +178,8 @@ subroutine package_defaults(package, root, error) return end if + package%implicit_none = .false. + end subroutine package_defaults diff --git a/src/fpm/manifest/package.f90 b/src/fpm/manifest/package.f90 index 043076143b..ab83e4d3f8 100644 --- a/src/fpm/manifest/package.f90 +++ b/src/fpm/manifest/package.f90 @@ -61,6 +61,8 @@ module fpm_manifest_package !> Name of the package character(len=:), allocatable :: name + logical :: implicit_none + !> Package version type(version_t) :: version diff --git a/src/fpm_model.f90 b/src/fpm_model.f90 index 9746e5f031..e3993415ba 100644 --- a/src/fpm_model.f90 +++ b/src/fpm_model.f90 @@ -111,6 +111,9 @@ module fpm_model !> Name of root package character(:), allocatable :: package_name + !> Should "implicit none" be enforced by the compiler + logical :: implicit_none + !> Array of packages (including the root package) type(package_t), allocatable :: packages(:) @@ -259,12 +262,20 @@ end function info_srcfile_short function info_model(model) result(s) type(fpm_model_t), intent(in) :: model - character(:), allocatable :: s + character(:), allocatable :: s, tmp integer :: i !type :: fpm_model_t s = "fpm_model_t(" ! character(:), allocatable :: package_name s = s // 'package_name="' // model%package_name // '"' + + if (model%implicit_none) then + tmp = ".true." + else + tmp = ".false." + end if + s = s // ', implicit_none=' // tmp + ! type(srcfile_t), allocatable :: sources(:) s = s // ", packages=[" do i = 1, size(model%packages) From 1e1077125f8e9b5cd206dccf813b8b3244116d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 29 Jun 2021 10:49:01 -0600 Subject: [PATCH 2/4] Read implicit_none from the toml file --- src/fpm/manifest.f90 | 2 -- src/fpm/manifest/package.f90 | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fpm/manifest.f90 b/src/fpm/manifest.f90 index 11409960be..8c39aa6915 100644 --- a/src/fpm/manifest.f90 +++ b/src/fpm/manifest.f90 @@ -178,8 +178,6 @@ subroutine package_defaults(package, root, error) return end if - package%implicit_none = .false. - end subroutine package_defaults diff --git a/src/fpm/manifest/package.f90 b/src/fpm/manifest/package.f90 index ab83e4d3f8..015bf20e1e 100644 --- a/src/fpm/manifest/package.f90 +++ b/src/fpm/manifest/package.f90 @@ -134,6 +134,9 @@ subroutine new_package(self, table, root, error) return end if + self%implicit_none = .false. + call get_value(table, "implicit_none", self%implicit_none) + if (len(self%name) <= 0) then call syntax_error(error, "Package name must be a non-empty string") return @@ -302,7 +305,7 @@ subroutine check(table, error) case("version", "license", "author", "maintainer", "copyright", & & "description", "keywords", "categories", "homepage", "build", & & "dependencies", "dev-dependencies", "test", "executable", & - & "example", "library", "install") + & "example", "library", "install", "implicit_none") continue end select From bcf5ea05f59bf70149bb62f6056636dd8d693f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 29 Jun 2021 10:58:55 -0600 Subject: [PATCH 3/4] Pass -fimplicit-none to the compiler from model --- src/fpm_backend.f90 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/fpm_backend.f90 b/src/fpm_backend.f90 index 8628ec45c6..09ae017d6b 100644 --- a/src/fpm_backend.f90 +++ b/src/fpm_backend.f90 @@ -257,7 +257,7 @@ subroutine build_target(model,target,stat) integer, intent(out) :: stat integer :: ilib, fh - character(:), allocatable :: link_flags + character(:), allocatable :: link_flags, implicit_flag if (.not.exists(dirname(target%output_file))) then call mkdir(dirname(target%output_file)) @@ -266,7 +266,12 @@ subroutine build_target(model,target,stat) select case(target%target_type) case (FPM_TARGET_OBJECT) - call run(model%fortran_compiler//" -c " // target%source%file_name // target%compile_flags & + if (model%implicit_none) then + implicit_flag = " -fimplicit-none" + else + implicit_flag = "" + end if + call run(model%fortran_compiler//" -c " // target%source%file_name // target%compile_flags // implicit_flag & // " -o " // target%output_file, echo=.true., exitstat=stat) case (FPM_TARGET_C_OBJECT) From 6da18937567300e10bb9a6269d120256b72f1532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 29 Jun 2021 12:05:07 -0600 Subject: [PATCH 4/4] Update src/fpm/manifest/package.f90 Co-authored-by: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> --- src/fpm/manifest/package.f90 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fpm/manifest/package.f90 b/src/fpm/manifest/package.f90 index 015bf20e1e..85965843d1 100644 --- a/src/fpm/manifest/package.f90 +++ b/src/fpm/manifest/package.f90 @@ -134,8 +134,7 @@ subroutine new_package(self, table, root, error) return end if - self%implicit_none = .false. - call get_value(table, "implicit_none", self%implicit_none) + call get_value(table, "implicit_none", self%implicit_none, .false.) if (len(self%name) <= 0) then call syntax_error(error, "Package name must be a non-empty string")