]> granicus.if.org Git - clang/commitdiff
PR16090: C++1y: treat undeduced 'auto' as a literal type, so that constexpr
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 21 May 2013 22:29:20 +0000 (22:29 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 21 May 2013 22:29:20 +0000 (22:29 +0000)
function templates can use it as a return type.

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

lib/AST/Type.cpp
test/SemaCXX/constant-expression-cxx1y.cpp

index eacf3678189c81da401e34b2966ccf71a55639ce..004e31af178d307b4496da953123f3ab4a8e794d 100644 (file)
@@ -1196,6 +1196,11 @@ bool Type::isLiteralType(ASTContext &Ctx) const {
     return true;
   }
 
+  // If this type hasn't been deduced yet, then conservatively assume that
+  // it'll work out to be a literal type.
+  if (isa<AutoType>(BaseTy->getCanonicalTypeInternal()))
+    return true;
+
   return false;
 }
 
index ea0c9e6526833d581d77ad554656aa722a77e30c..23b5d0b460f5c9996c9b818feed6a08ed7b71887 100644 (file)
@@ -708,3 +708,10 @@ namespace switch_stmt {
   static_assert(test_copy("hello world", 10), "");
   static_assert(test_copy("hello world", 10), "");
 }
+
+namespace deduced_return_type {
+  constexpr auto f() { return 0; }
+  template<typename T> constexpr auto g(T t) { return t; }
+  static_assert(f() == 0, "");
+  static_assert(g(true), "");
+}