Don't crash when binding a reference to a temporary pointer created from
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 Jan 2013 07:58:29 +0000 (07:58 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 Jan 2013 07:58:29 +0000 (07:58 +0000)
resolving an overloaded function reference within an initializer list.
Previously we would try to resolve the overloaded function reference without
first stripping off the InitListExpr wrapper.

llvm-svn: 172517

clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/cxx0x-initializer-references.cpp

index 94dd2aa..26bb6ef 100644 (file)
@@ -3024,6 +3024,10 @@ static void TryReferenceListInitialization(Sema &S,
         Sequence.RewrapReferenceInitList(cv1T1, InitList);
       return;
     }
+
+    // Update the initializer if we've resolved an overloaded function.
+    if (Sequence.step_begin() != Sequence.step_end())
+      Sequence.RewrapReferenceInitList(cv1T1, InitList);
   }
 
   // Not reference-related. Create a temporary and bind to that.
index c4e9c90..283c32a 100644 (file)
@@ -90,3 +90,10 @@ namespace PR12660 {
   const int &i { 1 };
   struct S { S(int); } const &s { 2 };
 }
+
+namespace b7891773 {
+  typedef void (*ptr)();
+  template <class T> void f();
+  int g(const ptr &);
+  int k = g({ f<int> });
+}