[Bug c++/105290] New: "Purely syntactic" disambiguation but GCC applies semantic rules for constant expressions
hstong at ca dot ibm.com
gcc-bugzilla@gcc.gnu.org
Sat Apr 16 03:56:47 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105290
Bug ID: 105290
Summary: "Purely syntactic" disambiguation but GCC applies
semantic rules for constant expressions
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: accepts-invalid, rejects-valid, wrong-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hstong at ca dot ibm.com
Target Milestone: ---
As far as parsing is concerned, a _constant-expression_ is just a
_conditional-expression_. There is no statement that a _constant-expression_
has to be semantically a constant expression to be parsed as one.
Every use of _constant-expression_ in the grammar is associated with a
case-specific (semantic) statement that applies the semantic constant
expression requirements.
It looks like GCC applies the semantic rules for constant expressions while
performing vexing parse disambiguation, which the standard says is "purely
syntactic".
Compiler Explorer link: https://godbolt.org/z/Ms38PPsqh
### SOURCE (`<stdin>`):
typedef int *Ptr;
int idx(unsigned *) { return 0; }
constexpr int idx(short *) { return 1; }
void zip(void **p) {
int val(Ptr (*p)[idx((short *)0)]); // constant expression in array
declarator
val(nullptr);
}
void zap(void **p) {
int val(Ptr(*p)[idx((unsigned *)0)]); // non-constant expression in subscript
expression?!
val(nullptr);
}
### ACTUAL OUTPUT:
<stdin>: In function 'void zap(void**)':
<stdin>:10:6: error: 'val' cannot be used as a function
### EXPECTED OUTPUT:
(Clean compile)
### COMPILER INVOCATION:
g++ -fsyntax-only -Wno-vexing-parse -xc++ -
### COMPILER VERSION INFO (`g++ -v`):
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/12.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.1 20220415 (experimental) (GCC)
More information about the Gcc-bugs
mailing list