[flang-commits] [flang] [flang] Reject PARAMETER constants in NAMELIST groups (PR #178960)

Miguel Saldivar via flang-commits flang-commits at lists.llvm.org
Fri Jan 30 12:47:29 PST 2026


https://github.com/Saldivarcher created https://github.com/llvm/llvm-project/pull/178960

The Fortran standard does not allow `PARAMETERS` within a `namelist-group-object`, it should only allow variables. An error should be emitted when a `PARAMETER` is found within a `namelist-group-object`.

Fixes: #178955 

>From adcedee12001f4ab93c451eff5ba39fe07a10d19 Mon Sep 17 00:00:00 2001
From: Miguel Saldivar <miguel.saldivar at hpe.com>
Date: Fri, 30 Jan 2026 14:42:45 -0600
Subject: [PATCH] [flang] Reject PARAMETER constants in NAMELIST groups

The Fortran standard does not allow `PARAMETERS` within a
`namelist-group-object`, it should only allow variables.
An error should be emitted when a `PARAMETER` is found within a
`namelist-group-object`.
---
 flang/lib/Semantics/check-namelist.cpp | 7 +++++++
 flang/test/Semantics/namelist02.f90    | 8 ++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 flang/test/Semantics/namelist02.f90

diff --git a/flang/lib/Semantics/check-namelist.cpp b/flang/lib/Semantics/check-namelist.cpp
index c2804c5d874e9..9b7ee30954521 100644
--- a/flang/lib/Semantics/check-namelist.cpp
+++ b/flang/lib/Semantics/check-namelist.cpp
@@ -28,6 +28,13 @@ void NamelistChecker::Leave(const parser::NamelistStmt &nmlStmt) {
                 "PUBLIC namelist"_err_en_US,
                 nmlObjSymbol->name());
           }
+          // `namelist-group-object` may only contain variables.
+          if (nmlObjSymbol->attrs().test(Attr::PARAMETER)) {
+            context_.Say(nmlObjName.source,
+                "A namelist group object '%s' must not be a "
+                "PARAMETER"_err_en_US,
+                nmlObjSymbol->name());
+          }
         }
       }
     }
diff --git a/flang/test/Semantics/namelist02.f90 b/flang/test/Semantics/namelist02.f90
new file mode 100644
index 0000000000000..def81d466bd58
--- /dev/null
+++ b/flang/test/Semantics/namelist02.f90
@@ -0,0 +1,8 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+program p
+  implicit none
+  integer, parameter :: k = 3
+  !ERROR: A namelist group object 'k' must not be a PARAMETER
+  namelist /g/ k
+end program



More information about the flang-commits mailing list