[cfe-commits] r57136 - in /cfe/trunk: lib/Parse/ParseTentative.cpp test/SemaCXX/decl-expr-ambiguity.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Sun Oct 5 14:10:10 PDT 2008


Author: akirtzidis
Date: Sun Oct  5 16:10:08 2008
New Revision: 57136

URL: http://llvm.org/viewvc/llvm-project?rev=57136&view=rev
Log:
Add some text from the C++ standard and additional ambiguity resolution tests.
No funcitonality change.

Modified:
    cfe/trunk/lib/Parse/ParseTentative.cpp
    cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=57136&r1=57135&r2=57136&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Sun Oct  5 16:10:08 2008
@@ -282,16 +282,24 @@
   return TPR == TPResult::True();
 }
 
-/// isCXXTypeIdInParens - Assumes that a '(' was parsed and now we want to
-/// know whether the parens contain an expression or a type-id.
-/// Returns true for a type-id and false for an expression.
-/// If during the disambiguation process a parsing error is encountered,
-/// the function returns true to let the declaration parsing code handle it.
-///
-/// type-id:
+/// isCXXTypeIdInParens - Assumes that a '(' was parsed and now we want to
+/// know whether the parens contain an expression or a type-id.
+/// Returns true for a type-id and false for an expression.
+/// If during the disambiguation process a parsing error is encountered,
+/// the function returns true to let the declaration parsing code handle it.
+///
+/// type-id:
 ///   type-specifier-seq abstract-declarator[opt]
 ///
 bool Parser::isCXXTypeIdInParens() {
+
+  // C++ 8.2p2:
+  // 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.
+
   TPResult TPR = isCXXDeclarationSpecifier();
   if (TPR != TPResult::Ambiguous())
     return TPR != TPResult::False(); // Returns true for TPResult::True() or
@@ -706,6 +714,16 @@
 ///         exception-specification[opt]
 ///
 bool Parser::isCXXFunctionDeclarator() {
+
+  // C++ 8.2p1:
+  // The ambiguity arising from the similarity between a function-style cast and
+  // a declaration mentioned in 6.8 can also occur in the context of a
+  // declaration. In that context, the choice is between a function declaration
+  // with a redundant set of parentheses around a parameter name and an object
+  // declaration with a function-style cast as the initializer. Just as for the
+  // ambiguities mentioned in 6.8, the resolution is to consider any construct
+  // that could possibly be a declaration a declaration.
+
   TentativeParsingAction PA(*this);
 
   ConsumeParen();

Modified: cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp?rev=57136&r1=57135&r2=57136&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp (original)
+++ cfe/trunk/test/SemaCXX/decl-expr-ambiguity.cpp Sun Oct  5 16:10:08 2008
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify %s 
+// RUN: clang -fsyntax-only -verify -pedantic-errors %s 
 
 void f() {
   int a;
@@ -14,7 +14,12 @@
   if (int(a)+1) {}
   for (int(a)+1;;) {}
   a = sizeof(int()+1);
+  a = sizeof(int(1));
   typeof(int()+1) a2;
+  (int(1)); // expected-warning {{expression result unused}}
+
+  // type-id
+  (int())1; // expected-error {{used type 'int ()' where arithmetic or pointer type is required}}
 
   // Declarations.
   T(*d)(int(p)); // expected-warning {{statement was disambiguated as declaration}} expected-error {{previous definition is here}}
@@ -25,3 +30,13 @@
   if (int(a)=1) {}
   int(d3(int())); // expected-warning {{statement was disambiguated as declaration}}
 }
+
+class C { };
+void fn(int(C)) { } // void fn(int(*fp)(C c)) { }
+                    // not: void fn(int C);
+int g(C);
+
+void foo() {
+  fn(1); // expected-error {{incompatible integer to pointer conversion passing 'int', expected 'int (*)(class C)'}}
+  fn(g); // OK
+}





More information about the cfe-commits mailing list