[cfe-commits] r80369 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/overload-value-dep-arg.cpp
Anders Carlsson
andersca at mac.com
Fri Aug 28 08:55:57 PDT 2009
Author: andersca
Date: Fri Aug 28 10:55:56 2009
New Revision: 80369
URL: http://llvm.org/viewvc/llvm-project?rev=80369&view=rev
Log:
When doing overload resolution, expressions that are value dependent but not type dependent and of integral type should not be treated as null pointer constants.
Added:
cfe/trunk/test/SemaCXX/overload-value-dep-arg.cpp
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=80369&r1=80368&r2=80369&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Aug 28 10:55:56 2009
@@ -870,6 +870,18 @@
return Context.getPointerType(CanonToPointee.getQualifiedType(Quals));
}
+static bool isNullPointerConstantForConversion(Expr *Expr,
+ bool InOverloadResolution,
+ ASTContext &Context) {
+ // Handle value-dependent integral null pointer constants correctly.
+ // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
+ if (Expr->isValueDependent() && !Expr->isTypeDependent() &&
+ Expr->getType()->isIntegralType())
+ return !InOverloadResolution;
+
+ return Expr->isNullPointerConstant(Context);
+}
+
/// IsPointerConversion - Determines whether the conversion of the
/// expression From, which has the (possibly adjusted) type FromType,
/// can be converted to the type ToType via a pointer conversion (C++
@@ -897,7 +909,7 @@
// Conversion from a null pointer constant to any Objective-C pointer type.
if (ToType->isObjCObjectPointerType() &&
- From->isNullPointerConstant(Context)) {
+ isNullPointerConstantForConversion(From, InOverloadResolution, Context)) {
ConvertedType = ToType;
return true;
}
@@ -910,14 +922,16 @@
}
// Blocks: A null pointer constant can be converted to a block
// pointer type.
- if (ToType->isBlockPointerType() && From->isNullPointerConstant(Context)) {
+ if (ToType->isBlockPointerType() &&
+ isNullPointerConstantForConversion(From, InOverloadResolution, Context)) {
ConvertedType = ToType;
return true;
}
// If the left-hand-side is nullptr_t, the right side can be a null
// pointer constant.
- if (ToType->isNullPtrType() && From->isNullPointerConstant(Context)) {
+ if (ToType->isNullPtrType() &&
+ isNullPointerConstantForConversion(From, InOverloadResolution, Context)) {
ConvertedType = ToType;
return true;
}
@@ -927,7 +941,7 @@
return false;
// A null pointer constant can be converted to a pointer type (C++ 4.10p1).
- if (From->isNullPointerConstant(Context)) {
+ if (isNullPointerConstantForConversion(From, InOverloadResolution, Context)) {
ConvertedType = ToType;
return true;
}
Added: cfe/trunk/test/SemaCXX/overload-value-dep-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-value-dep-arg.cpp?rev=80369&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-value-dep-arg.cpp (added)
+++ cfe/trunk/test/SemaCXX/overload-value-dep-arg.cpp Fri Aug 28 10:55:56 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+class C {
+ C(void*);
+};
+
+int f(const C&);
+int f(unsigned long);
+
+template<typename T> int f(const T* t) {
+ return f(reinterpret_cast<unsigned long>(t));
+}
+
More information about the cfe-commits
mailing list