]> granicus.if.org Git - clang/commitdiff
Deal with an icky corner case where we were complaining that a catch
authorDouglas Gregor <dgregor@apple.com>
Mon, 18 May 2009 21:08:14 +0000 (21:08 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 18 May 2009 21:08:14 +0000 (21:08 +0000)
statement was using an rvalue reference during the template
definition. However, template instantiations based on an lvalue
reference type are well-formed, so we delay checking of these property
until template instantiation time.

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

lib/Sema/SemaDeclCXX.cpp
test/SemaTemplate/instantiate-try-catch.cpp [new file with mode: 0644]

index d968bc6b75afb3da8db87e3723218e159eafd4a6..78123015a37bf79c83699d770441bd591493c546 100644 (file)
@@ -2553,7 +2553,7 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, QualType ExDeclType,
   // The exception-declaration shall not denote a pointer or reference to an
   // incomplete type, other than [cv] void*.
   // N2844 forbids rvalue references.
-  if(ExDeclType->isRValueReferenceType()) {
+  if(!ExDeclType->isDependentType() && ExDeclType->isRValueReferenceType()) {
     Diag(Loc, diag::err_catch_rvalue_ref) << Range;
     Invalid = true;
   }
diff --git a/test/SemaTemplate/instantiate-try-catch.cpp b/test/SemaTemplate/instantiate-try-catch.cpp
new file mode 100644 (file)
index 0000000..074afa9
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: clang-cc -fsyntax-only -std=c++0x -verify %s
+
+template<typename T> struct TryCatch0 {
+  void f() {
+    try {
+    } catch (T&&) { // expected-error 2{{cannot catch exceptions by rvalue reference}}
+    }
+  }
+};
+
+template struct TryCatch0<int&>; // okay
+template struct TryCatch0<int&&>; // expected-note{{instantiation}}
+template struct TryCatch0<int>; // expected-note{{instantiation}}
+