diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -1280,6 +1280,12 @@ CheckConflicting(symbol, Attr::POINTER, Attr::TARGET); CheckConflicting(symbol, Attr::POINTER, Attr::ALLOCATABLE); // C751 CheckConflicting(symbol, Attr::POINTER, Attr::INTRINSIC); + // Prohibit constant pointers. The standard does not explicitly prohibit + // them, but the PARAMETER attribute requires a entity-decl to have an + // initialization that is a constant-expr, and the only form of + // initialization that allows a constant-expr is the one that's not a "=>" + // pointer initialization. See C811, C807, and section 8.5.13. + CheckConflicting(symbol, Attr::POINTER, Attr::PARAMETER); if (symbol.Corank() > 0) { messages_.Say( "'%s' may not have the POINTER attribute because it is a coarray"_err_en_US, diff --git a/flang/test/Semantics/resolve90.f90 b/flang/test/Semantics/resolve90.f90 --- a/flang/test/Semantics/resolve90.f90 +++ b/flang/test/Semantics/resolve90.f90 @@ -1,10 +1,13 @@ ! RUN: %S/test_errors.sh %s %t %f18 +! Testing for pointer constant, along with : ! C751 A component shall not have both the ALLOCATABLE and POINTER attributes. ! C752 If the CONTIGUOUS attribute is specified, the component shall be an ! array with the POINTER attribute. ! C753 The * char-length option is permitted only if the component is of type ! character. subroutine s() + !ERROR: 'nullint' may not have both the POINTER and PARAMETER attributes + integer, pointer, parameter :: nullint => null() type derivedType !ERROR: 'pointerallocatablefield' may not have both the POINTER and ALLOCATABLE attributes real, pointer, allocatable :: pointerAllocatableField