Skip to content

Commit 93424e9

Browse files
committed
CWG1223 Proposed resolution for CWG1223
[dcl.ambig.res] Use "is to be considered a" instead of "is" to avoid redefining the grammar production /type-id/. [stmt.ambig] Likewise, don't \grammarterm "declaration" in "is a declaration" to avoid redefining /declaration/. [stmt.ambig] Reword comment in example for consistency.
1 parent ae4cba4 commit 93424e9

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

source/declarations.tex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,11 @@
23712371
such as the potential parameter declaration,
23722372
that could possibly be a declaration
23732373
to be a declaration.
2374+
However, a construct that can syntactically be a \grammarterm{declaration}
2375+
whose outermost \grammarterm{declarator}
2376+
would match the grammar of a \grammarterm{declarator}
2377+
with a \grammarterm{trailing-return-type}
2378+
is a declaration only if it starts with \keyword{auto}.
23742379
\begin{note}
23752380
A declaration can be explicitly disambiguated by adding parentheses
23762381
around the argument.
@@ -2382,13 +2387,16 @@
23822387
struct S {
23832388
S(int);
23842389
};
2390+
typedef struct BB { int C[2]; } *B, C;
23852391

23862392
void foo(double a) {
23872393
S w(int(a)); // function declaration
23882394
S x(int()); // function declaration
23892395
S y((int(a))); // object declaration
23902396
S y((int)a); // object declaration
23912397
S z = int(a); // object declaration
2398+
S a(B()->C); // object declaration
2399+
S b(auto()->C); // function declaration
23922400
}
23932401
\end{codeblock}
23942402
\end{example}
@@ -2401,6 +2409,11 @@
24012409
\grammarterm{type-id}
24022410
in its syntactic context shall be considered a
24032411
\grammarterm{type-id}.
2412+
However, a construct that can syntactically be a \grammarterm{type-id}
2413+
whose outermost \grammarterm{abstract-declarator}
2414+
would match the grammar of an \grammarterm{abstract-declarator}
2415+
with a \grammarterm{trailing-return-type}
2416+
is to be considered a \grammarterm{type-id} only if it starts with \keyword{auto}.
24042417
\begin{example}
24052418
\begin{codeblock}
24062419
template <class T> struct X {};
@@ -2419,6 +2432,12 @@
24192432
(int(a))+1; // expression
24202433
(int(unsigned(a)))+1; // type-id (ill-formed)
24212434
}
2435+
2436+
typedef struct BB { int C[2]; } *B, C;
2437+
void g() {
2438+
sizeof(B()->C[1]); // OK, \tcode{sizeof(}expression\tcode{)}
2439+
sizeof(auto()->C[1]); // error: \tcode{sizeof} of a function returning an array
2440+
}
24222441
\end{codeblock}
24232442
\end{example}
24242443

source/statements.tex

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,9 @@
10811081
conversion\iref{expr.type.conv} as its leftmost subexpression can be
10821082
indistinguishable from a \grammarterm{declaration} where the first
10831083
\grammarterm{declarator} starts with a \tcode{(}. In those cases the
1084-
\grammarterm{statement} is a \grammarterm{declaration}.
1084+
% FIXME: Shouldn't "\grammarterm{declaration}" be "declaration" here?
1085+
\grammarterm{statement} is a \grammarterm{declaration},
1086+
except as specified below.
10851087

10861088
\pnum
10871089
\begin{note}
@@ -1163,4 +1165,35 @@
11631165
}
11641166
\end{codeblock}
11651167
\end{example}
1168+
1169+
\pnum
1170+
A syntactically ambiguous statement that can syntactically be
1171+
a \grammarterm{declaration} with an outermost \grammarterm{declarator}
1172+
with a \grammarterm{trailing-return-type}
1173+
is a declaration only if it starts with \keyword{auto}.
1174+
\begin{example}
1175+
\begin{codeblock}
1176+
struct M;
1177+
struct S {
1178+
S* operator()();
1179+
int N;
1180+
int M;
1181+
1182+
void mem(S s) {
1183+
auto(s)()->M; // expression, \tcode{S::M} hides \tcode{::M}
1184+
}
1185+
};
1186+
1187+
void f(S s) {
1188+
{
1189+
auto(s)()->N; // expression
1190+
auto(s)()->M; // function declaration
1191+
}
1192+
{
1193+
S(s)()->N; // expression
1194+
S(s)()->M; // expression
1195+
}
1196+
}
1197+
\end{codeblock}
1198+
\end{example}
11661199
\indextext{statement|)}

0 commit comments

Comments
 (0)