Skip to content

Commit baea8ec

Browse files
authored
Merge 2023-06 CWG Motion 7
[Motion cwg 7] P2915R0 (Proposed resolution for CWG1223)
2 parents eb712ad + 9b9ebcc commit baea8ec

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-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 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{\keyword{sizeof}(}expression\tcode{)}
2439+
sizeof(auto()->C[1]); // error: \keyword{sizeof} of a function returning an array
2440+
}
24222441
\end{codeblock}
24232442
\end{example}
24242443

source/statements.tex

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,8 @@
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+
\grammarterm{statement} is considered a \grammarterm{declaration},
1085+
except as specified below.
10851086

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

0 commit comments

Comments
 (0)