[cfe-commits] r166644 - in /cfe/trunk: lib/Sema/SemaType.cpp test/SemaCXX/constant-expression-cxx11.cpp test/SemaCXX/function-type-qual.cpp

Richard Smith richard-llvm at metafoo.co.uk
Wed Oct 24 16:51:56 PDT 2012


Author: rsmith
Date: Wed Oct 24 18:51:56 2012
New Revision: 166644

URL: http://llvm.org/viewvc/llvm-project?rev=166644&view=rev
Log:
PR14171: Don't crash if we hit one of the paths where GetFullTypeForDeclarator
rebuilds a function type, and that function type has parens around its name.

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
    cfe/trunk/test/SemaCXX/function-type-qual.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=166644&r1=166643&r2=166644&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Oct 24 18:51:56 2012
@@ -2661,6 +2661,9 @@
 
     // C++0x [dcl.constexpr]p8: A constexpr specifier for a non-static member
     // function that is not a constructor declares that function to be const.
+    // FIXME: This should be deferred until we know whether this is a static
+    //        member function (for an out-of-class definition, we don't know
+    //        this until we perform redeclaration lookup).
     if (D.getDeclSpec().isConstexprSpecified() && !FreeFunction &&
         D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static &&
         D.getName().getKind() != UnqualifiedId::IK_ConstructorName &&
@@ -2672,6 +2675,12 @@
       T = Context.getFunctionType(FnTy->getResultType(),
                                   FnTy->arg_type_begin(),
                                   FnTy->getNumArgs(), EPI);
+      // Rebuild any parens around the identifier in the function type.
+      for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
+        if (D.getTypeObject(i).Kind != DeclaratorChunk::Paren)
+          break;
+        T = S.BuildParenType(T);
+      }
     }
 
     // C++11 [dcl.fct]p6 (w/DR1417):
@@ -2725,6 +2734,12 @@
       T = Context.getFunctionType(FnTy->getResultType(),
                                   FnTy->arg_type_begin(),
                                   FnTy->getNumArgs(), EPI);
+      // Rebuild any parens around the identifier in the function type.
+      for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) {
+        if (D.getTypeObject(i).Kind != DeclaratorChunk::Paren)
+          break;
+        T = S.BuildParenType(T);
+      }
     }
   }
 

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=166644&r1=166643&r2=166644&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Wed Oct 24 18:51:56 2012
@@ -741,6 +741,15 @@
 static_assert(S(5) == 11, "");
 static_assert(check(S(5), 11), "");
 
+namespace PR14171 {
+
+struct X {
+  constexpr (operator int)() { return 0; }
+};
+static_assert(X() == 0, "");
+
+}
+
 }
 
 }

Modified: cfe/trunk/test/SemaCXX/function-type-qual.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-type-qual.cpp?rev=166644&r1=166643&r2=166644&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-type-qual.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-type-qual.cpp Wed Oct 24 18:51:56 2012
@@ -26,3 +26,6 @@
 
 void (C::*mpf)() const;
 cfn C::*mpg;
+
+// Don't crash!
+void (PR14171)() const; // expected-error {{non-member function cannot have 'const' qualifier}}





More information about the cfe-commits mailing list