Skip to content

Commit f2897b8

Browse files
committed
[flang] Disallow pointer constants
None of the other Fortran compilers allow them. Differential Revision: https://reviews.llvm.org/D89581
1 parent 978fbd8 commit f2897b8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,12 @@ void CheckHelper::CheckPointer(const Symbol &symbol) { // C852
12801280
CheckConflicting(symbol, Attr::POINTER, Attr::TARGET);
12811281
CheckConflicting(symbol, Attr::POINTER, Attr::ALLOCATABLE); // C751
12821282
CheckConflicting(symbol, Attr::POINTER, Attr::INTRINSIC);
1283+
// Prohibit constant pointers. The standard does not explicitly prohibit
1284+
// them, but the PARAMETER attribute requires a entity-decl to have an
1285+
// initialization that is a constant-expr, and the only form of
1286+
// initialization that allows a constant-expr is the one that's not a "=>"
1287+
// pointer initialization. See C811, C807, and section 8.5.13.
1288+
CheckConflicting(symbol, Attr::POINTER, Attr::PARAMETER);
12831289
if (symbol.Corank() > 0) {
12841290
messages_.Say(
12851291
"'%s' may not have the POINTER attribute because it is a coarray"_err_en_US,

flang/test/Semantics/resolve90.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
! RUN: %S/test_errors.sh %s %t %f18
2+
! Testing for pointer constant, along with :
23
! C751 A component shall not have both the ALLOCATABLE and POINTER attributes.
34
! C752 If the CONTIGUOUS attribute is specified, the component shall be an
45
! array with the POINTER attribute.
56
! C753 The * char-length option is permitted only if the component is of type
67
! character.
78
subroutine s()
9+
!ERROR: 'nullint' may not have both the POINTER and PARAMETER attributes
10+
integer, pointer, parameter :: nullint => null()
811
type derivedType
912
!ERROR: 'pointerallocatablefield' may not have both the POINTER and ALLOCATABLE attributes
1013
real, pointer, allocatable :: pointerAllocatableField

0 commit comments

Comments
 (0)