]> granicus.if.org Git - clang/commitdiff
constexpr: Unlike other incomplete types, 'void' cannot possibly be completed as
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Feb 2012 04:40:02 +0000 (04:40 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Feb 2012 04:40:02 +0000 (04:40 +0000)
a literal type. Disallow it as the return type of a constexpr function
declaration.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149469 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp

index 280a60e5de39b869a0a5b432c8c781bf203f1e49..684f355bfbcdac5bb1c19f0b1d83cba0254fa651 100644 (file)
@@ -4212,7 +4212,8 @@ bool Sema::RequireLiteralType(SourceLocation Loc, QualType T,
   assert(!T->isDependentType() && "type should not be dependent");
 
   bool Incomplete = RequireCompleteType(Loc, T, 0);
-  if (T->isLiteralType() || (AllowIncompleteType && Incomplete))
+  if (T->isLiteralType() ||
+      (AllowIncompleteType && Incomplete && !T->isVoidType()))
     return false;
 
   if (PD.getDiagID() == 0)
index 6e4e5803d1cbbf13deb3fe6587db316a86a1bffc..19bcde66401f241ef4ee43ec2587f20d818d8b68 100644 (file)
@@ -40,6 +40,7 @@ struct T : SS, NonLiteral { // expected-note {{base class 'NonLiteral' of non-li
 
   //  - its return type shall be a literal type;
   constexpr NonLiteral NonLiteralReturn(); // expected-error {{constexpr function's return type 'NonLiteral' is not a literal type}}
+  constexpr void VoidReturn(); // expected-error {{constexpr function's return type 'void' is not a literal type}}
   constexpr ~T(); // expected-error {{destructor cannot be marked constexpr}}
   typedef NonLiteral F();
   constexpr F NonLiteralReturn2; // expected-error {{constexpr function's return type 'NonLiteral' is not a literal type}}