]> granicus.if.org Git - clang/commitdiff
Attempt to resolve overloaded functions in comma expressions and
authorDouglas Gregor <dgregor@apple.com>
Tue, 9 Nov 2010 21:07:58 +0000 (21:07 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 9 Nov 2010 21:07:58 +0000 (21:07 +0000)
conditional operators. Fixes PR7863.

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

lib/Sema/SemaExpr.cpp
test/SemaCXX/overloaded-name.cpp [new file with mode: 0644]

index 0d0f48cd743e60f07485347489bf760a01fe6c29..790f8831d2dd24dbe6719bac1a47f7b381a6ceee 100644 (file)
@@ -4309,6 +4309,21 @@ ExprResult Sema::ActOnParenOrParenListExpr(SourceLocation L,
 QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS,
                                         Expr *&SAVE,
                                         SourceLocation QuestionLoc) {
+  // If both LHS and RHS are overloaded functions, try to resolve them.
+  if (Context.hasSameType(LHS->getType(), RHS->getType()) && 
+      LHS->getType()->isSpecificBuiltinType(BuiltinType::Overload)) {
+    ExprResult LHSResult = CheckPlaceholderExpr(LHS, QuestionLoc);
+    if (LHSResult.isInvalid())
+      return QualType();
+
+    ExprResult RHSResult = CheckPlaceholderExpr(RHS, QuestionLoc);
+    if (RHSResult.isInvalid())
+      return QualType();
+
+    LHS = LHSResult.take();
+    RHS = RHSResult.take();
+  }
+
   // C++ is sufficiently different to merit its own checker.
   if (getLangOptions().CPlusPlus)
     return CXXCheckConditionalOperands(Cond, LHS, RHS, SAVE, QuestionLoc);
@@ -6250,6 +6265,15 @@ QualType Sema::CheckAssignmentOperands(Expr *LHS, Expr *&RHS,
 QualType Sema::CheckCommaOperands(Expr *LHS, Expr *&RHS, SourceLocation Loc) {
   DiagnoseUnusedExprResult(LHS);
 
+  ExprResult LHSResult = CheckPlaceholderExpr(LHS, Loc);
+  if (LHSResult.isInvalid()) 
+    return QualType();
+
+  ExprResult RHSResult = CheckPlaceholderExpr(RHS, Loc);
+  if (RHSResult.isInvalid())
+    return QualType();
+  RHS = RHSResult.take();
+
   // C's comma performs lvalue conversion (C99 6.3.2.1) on both its
   // operands, but not unary promotions.
   // C++'s comma does not do any conversions at all (C++ [expr.comma]p1).
diff --git a/test/SemaCXX/overloaded-name.cpp b/test/SemaCXX/overloaded-name.cpp
new file mode 100644 (file)
index 0000000..289d5c9
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int ovl(int);
+float ovl(float);
+
+template<typename T> T ovl(T);
+
+void test(bool b) {
+  (void)((void)0, ovl); // expected-error{{cannot resolve overloaded function from context}}
+  // PR7863
+  (void)(b? ovl : &ovl); // expected-error{{cannot resolve overloaded function from context}}
+  (void)(b? ovl<float> : &ovl); // expected-error{{cannot resolve overloaded function from context}}
+  (void)(b? ovl<float> : ovl<float>);
+}