Deprecated (legacy) string literal conversion to 'char *' causes strange overloading...
authorDmitry Polukhin <dmitry.polukhin@gmail.com>
Tue, 19 Jul 2016 11:29:16 +0000 (11:29 +0000)
committerDmitry Polukhin <dmitry.polukhin@gmail.com>
Tue, 19 Jul 2016 11:29:16 +0000 (11:29 +0000)
It's a patch for PR28050. Seems like overloading resolution wipes out
the first standard conversion sequence (before user-defined conversion)
in case of deprecated string literal conversion.

Differential revision: https://reviews.llvm.org/D21228

Patch by Alexander Makarov

llvm-svn: 275970

clang/include/clang/Sema/Overload.h
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/pr28050.cpp [new file with mode: 0644]

index d0f21cd..68678ad 100644 (file)
@@ -428,8 +428,11 @@ namespace clang {
     };
 
     ImplicitConversionSequence()
-      : ConversionKind(Uninitialized), StdInitializerListElement(false)
-    {}
+        : ConversionKind(Uninitialized), StdInitializerListElement(false) {
+      Standard.First = ICK_Identity;
+      Standard.Second = ICK_Identity;
+      Standard.Third = ICK_Identity;
+    }
     ~ImplicitConversionSequence() {
       destruct();
     }
index b025a39..dfb4cce 100644 (file)
@@ -1199,7 +1199,6 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
   case OR_Success:
   case OR_Deleted:
     ICS.setUserDefined();
-    ICS.UserDefined.Before.setAsIdentityConversion();
     // C++ [over.ics.user]p4:
     //   A conversion of an expression of class type to the same class
     //   type is given Exact Match rank, and a conversion of an
@@ -4540,7 +4539,6 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
       return ICS;
     }
 
-    ICS.UserDefined.Before.setAsIdentityConversion();
     ICS.UserDefined.After.ReferenceBinding = true;
     ICS.UserDefined.After.IsLvalueReference = !isRValRef;
     ICS.UserDefined.After.BindsToFunctionLvalue = false;
diff --git a/clang/test/SemaCXX/pr28050.cpp b/clang/test/SemaCXX/pr28050.cpp
new file mode 100644 (file)
index 0000000..57e90eb
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -std=c++11 %s -fsyntax-only
+//
+// expected-no-diagnostics
+
+class A {
+public:
+  A(char *s) {}
+  A(A &&) = delete;
+};
+
+int main() { A a("OK"); }