]> granicus.if.org Git - clang/commitdiff
Always add the built-in overload candidates for operators &&, ||, and
authorDouglas Gregor <dgregor@apple.com>
Mon, 10 Oct 2011 14:05:31 +0000 (14:05 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 10 Oct 2011 14:05:31 +0000 (14:05 +0000)
!. Fixes PR9865.

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

lib/Sema/SemaOverload.cpp
test/CXX/over/over.built/p23.cpp [new file with mode: 0644]

index c968498d00b7810c21b6fc382d5bf42546b644ca..c931160f76c2421473b9ea9715c2cee4937bfe53 100644 (file)
@@ -6375,7 +6375,11 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
 
   // Exit early when no non-record types have been added to the candidate set
   // for any of the arguments to the operator.
-  if (!HasNonRecordCandidateType)
+  //
+  // We can't exit early for !, ||, or &&, since there we have always have
+  // 'bool' overloads.
+  if (!HasNonRecordCandidateType && 
+      !(Op == OO_Exclaim || Op == OO_AmpAmp || Op == OO_PipePipe))
     return;
 
   // Setup an object to manage the common state for building overloads.
diff --git a/test/CXX/over/over.built/p23.cpp b/test/CXX/over/over.built/p23.cpp
new file mode 100644 (file)
index 0000000..c65b108
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++0x -verify %s
+
+struct Variant {
+  template <typename T> operator T();
+};
+
+Variant getValue();
+
+void testVariant() {
+  bool ret1 = getValue() || getValue(); 
+  bool ret2 = getValue() && getValue(); 
+  bool ret3 = !getValue();
+}
+
+struct ExplicitVariant {
+  template <typename T> explicit operator T();
+};
+
+ExplicitVariant getExplicitValue();
+
+void testExplicitVariant() {
+  bool ret1 = getExplicitValue() || getExplicitValue(); 
+  bool ret2 = getExplicitValue() && getExplicitValue(); 
+  bool ret3 = !getExplicitValue();
+}