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

via flang-commits flang-commits at lists.llvm.org
Fri Jan 30 12:48:07 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Miguel Saldivar (Saldivarcher)

<details>
<summary>Changes</summary>

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 

---
Full diff: https://github.com/llvm/llvm-project/pull/178960.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-namelist.cpp (+7) 
- (added) flang/test/Semantics/namelist02.f90 (+8) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list