[cfe-commits] r114331 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CXX/expr/expr.unary/expr.unary.op/p6.cpp

Douglas Gregor dgregor at apple.com
Mon Sep 20 10:13:33 PDT 2010


Author: dgregor
Date: Mon Sep 20 12:13:33 2010
New Revision: 114331

URL: http://llvm.org/viewvc/llvm-project?rev=114331&view=rev
Log:
Check that an overloaded function name, when used by the ! operator,
actually resolves to a particular function. Fixes PR8181, from Faisal
Vali!


Added:
    cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=114331&r1=114330&r2=114331&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 20 12:13:33 2010
@@ -6814,6 +6814,13 @@
     if (!resultType->isScalarType()) // C99 6.5.3.3p1
       return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
         << resultType << Input->getSourceRange());
+    
+    // Do not accept &f if f is overloaded
+    // i.e. void f(int); void f(char); bool b = &f;
+    if (resultType == Context.OverloadTy && 
+        PerformContextuallyConvertToBool(Input)) 
+      return ExprError(); // Diagnostic is uttered above
+
     // LNot always has type int. C99 6.5.3.3p5.
     // In C++, it's bool. C++ 5.3.1p8
     resultType = getLangOptions().CPlusPlus ? Context.BoolTy : Context.IntTy;

Added: cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp?rev=114331&view=auto
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp (added)
+++ cfe/trunk/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp Mon Sep 20 12:13:33 2010
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// -- prvalue of arithmetic
+
+bool b = !0;
+
+bool b2 = !1.2;
+
+bool b3 = !4;
+
+// -- unscoped enumeration
+enum { E, F };
+
+bool b4 = !E;
+bool b5 = !F;
+
+// --  pointer, 
+bool b6 = !&b4;
+void f();
+bool b61 = !&f;
+
+// -- or pointer to member type can be converted to a prvalue of type bool.
+struct S { void f() { } };
+
+bool b7 = !&S::f;
+
+
+bool b8 = !S(); //expected-error {{invalid argument type 'S'}}
+
+namespace PR8181
+{
+  void f() { }
+  void f(char) { }
+  bool b = !&f;  //expected-error {{value of type '<overloaded function type>' is not contextually convertible to 'bool'}}
+
+}





More information about the cfe-commits mailing list