http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56037
Bug #: 56037
Summary: Spurious syntax error triggered before ambiguity
resolution of type-id
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
A spurious syntax error is produced by the following:
static const int zero = 0;
std::cout << (std::pair<int, int>(int(zero), int(zero))) << std::endl;
In contrast,
static const int zero = 0;
static const int zero_alias = 0;
std::cout << (std::pair<int, int>(int(zero), int(zero_alias))) << std::endl;
compiles correctly (assuming that there is an appropriate overload for
operator<<).
Section 8.2[2] states that
The ambiguity arising from the similarity between a function-style cast and a
type-id can occur in different contexts. The ambiguity appears as a choice
between a function-style cast expression and a declaration of a type. The
resolution is that any construct that could possibly be a type-id in its
syntactic context shall be considered a type-id.
In this case, 8.2[2] should not apply, since the syntactic context of the
parenthesized expression does not permit the production:
cast-expression :: ( type-id ) cast-expression
However, in the first code excerpt, where the parenthesized expression would
not be a valid type-id (because of the redefinition of the parameter name), the
syntax error is apparently being triggered before the ambiguity resolution
decides that type-id is not possible. In the second code excerpt, the
parenthesize expression could contain a valid type-id, but ambiguity resolution
rejects that possibility.
---
Bug report generated as a result of
http://stackoverflow.com/questions/14403946/adding-parenthesis-to-a-constructor-call-causes-duplicate-parameter-error-in-xlc/14404900#14404900