public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56037] New: Spurious syntax error triggered before ambiguity resolution of type-id
@ 2013-01-18 20:14 ricilake at gmail dot com
  2013-01-18 20:23 ` [Bug c++/56037] " ricilake at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ricilake at gmail dot com @ 2013-01-18 20:14 UTC (permalink / raw)
  To: gcc-bugs


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: unassigned@gcc.gnu.org
        ReportedBy: ricilake@gmail.com


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-11-02  9:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-18 20:14 [Bug c++/56037] New: Spurious syntax error triggered before ambiguity resolution of type-id ricilake at gmail dot com
2013-01-18 20:23 ` [Bug c++/56037] " ricilake at gmail dot com
2013-01-19 14:35 ` redi at gcc dot gnu.org
2013-07-03  9:49 ` paolo.carlini at oracle dot com
2013-10-31 17:41 ` paolo.carlini at oracle dot com
2013-11-02  9:34 ` paolo at gcc dot gnu.org
2013-11-02  9:35 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).