[cfe-commits] r97128 - in /cfe/trunk: lib/Sema/SemaOverload.cpp lib/Sema/SemaOverload.h test/Sema/overloadable-complex.c test/SemaCXX/complex-overload.cpp

Chandler Carruth chandlerc at gmail.com
Wed Feb 24 23:20:54 PST 2010


Author: chandlerc
Date: Thu Feb 25 01:20:54 2010
New Revision: 97128

URL: http://llvm.org/viewvc/llvm-project?rev=97128&view=rev
Log:
Add a new conversion rank to classify conversions between complex and scalar
types. Rank these conversions below other conversions. This allows overload
resolution when the only distinction is between a complex and scalar type. It
also brings the complex overload resolutin in line with GCC's.

Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/lib/Sema/SemaOverload.h
    cfe/trunk/test/Sema/overloadable-complex.c
    cfe/trunk/test/SemaCXX/complex-overload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=97128&r1=97127&r2=97128&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Feb 25 01:20:54 2010
@@ -80,7 +80,7 @@
     ICR_Conversion,
     ICR_Conversion,
     ICR_Conversion,
-    ICR_Conversion
+    ICR_Complex_Real_Conversion
   };
   return Rank[(int)Kind];
 }
@@ -669,14 +669,19 @@
     // Integral conversions (C++ 4.7).
     SCS.Second = ICK_Integral_Conversion;
     FromType = ToType.getUnqualifiedType();
-  } else if (FromType->isFloatingType() && ToType->isFloatingType()) {
-    // Floating point conversions (C++ 4.8).
-    SCS.Second = ICK_Floating_Conversion;
-    FromType = ToType.getUnqualifiedType();
   } else if (FromType->isComplexType() && ToType->isComplexType()) {
     // Complex conversions (C99 6.3.1.6)
     SCS.Second = ICK_Complex_Conversion;
     FromType = ToType.getUnqualifiedType();
+  } else if ((FromType->isComplexType() && ToType->isArithmeticType()) ||
+             (ToType->isComplexType() && FromType->isArithmeticType())) {
+    // Complex-real conversions (C99 6.3.1.7)
+    SCS.Second = ICK_Complex_Real;
+    FromType = ToType.getUnqualifiedType();
+  } else if (FromType->isFloatingType() && ToType->isFloatingType()) {
+    // Floating point conversions (C++ 4.8).
+    SCS.Second = ICK_Floating_Conversion;
+    FromType = ToType.getUnqualifiedType();
   } else if ((FromType->isFloatingType() &&
               ToType->isIntegralType() && (!ToType->isBooleanType() &&
                                            !ToType->isEnumeralType())) ||
@@ -685,11 +690,6 @@
     // Floating-integral conversions (C++ 4.9).
     SCS.Second = ICK_Floating_Integral;
     FromType = ToType.getUnqualifiedType();
-  } else if ((FromType->isComplexType() && ToType->isArithmeticType()) ||
-             (ToType->isComplexType() && FromType->isArithmeticType())) {
-    // Complex-real conversions (C99 6.3.1.7)
-    SCS.Second = ICK_Complex_Real;
-    FromType = ToType.getUnqualifiedType();
   } else if (IsPointerConversion(From, FromType, ToType, InOverloadResolution,
                                  FromType, IncompatibleObjC)) {
     // Pointer conversions (C++ 4.10).

Modified: cfe/trunk/lib/Sema/SemaOverload.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.h?rev=97128&r1=97127&r2=97128&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.h (original)
+++ cfe/trunk/lib/Sema/SemaOverload.h Thu Feb 25 01:20:54 2010
@@ -54,12 +54,12 @@
     ICK_Floating_Conversion,   ///< Floating point conversions (C++ 4.8)
     ICK_Complex_Conversion,    ///< Complex conversions (C99 6.3.1.6)
     ICK_Floating_Integral,     ///< Floating-integral conversions (C++ 4.9)
-    ICK_Complex_Real,          ///< Complex-real conversions (C99 6.3.1.7)
     ICK_Pointer_Conversion,    ///< Pointer conversions (C++ 4.10)
     ICK_Pointer_Member,        ///< Pointer-to-member conversions (C++ 4.11)
     ICK_Boolean_Conversion,    ///< Boolean conversions (C++ 4.12)
     ICK_Compatible_Conversion, ///< Conversions between compatible types in C99
     ICK_Derived_To_Base,       ///< Derived-to-base (C++ [over.best.ics])
+    ICK_Complex_Real,          ///< Complex-real conversions (C99 6.3.1.7)
     ICK_Num_Conversion_Kinds   ///< The number of conversion kinds
   };
 
@@ -83,9 +83,10 @@
   /// 13.3.3.1.1) and are listed such that better conversion ranks
   /// have smaller values.
   enum ImplicitConversionRank {
-    ICR_Exact_Match = 0, ///< Exact Match
-    ICR_Promotion,       ///< Promotion
-    ICR_Conversion       ///< Conversion
+    ICR_Exact_Match = 0,        ///< Exact Match
+    ICR_Promotion,              ///< Promotion
+    ICR_Conversion,             ///< Conversion
+    ICR_Complex_Real_Conversion ///< Complex <-> Real conversion
   };
 
   ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);

Modified: cfe/trunk/test/Sema/overloadable-complex.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/overloadable-complex.c?rev=97128&r1=97127&r2=97128&view=diff
==============================================================================
--- cfe/trunk/test/Sema/overloadable-complex.c (original)
+++ cfe/trunk/test/Sema/overloadable-complex.c Thu Feb 25 01:20:54 2010
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-char *foo(float) __attribute__((__overloadable__)); // expected-note 3 {{candidate function}}
+char *foo(float) __attribute__((__overloadable__));
 
 void test_foo_1(float fv, double dv, float _Complex fc, double _Complex dc) {
   char *cp1 = foo(fv);
@@ -9,20 +9,20 @@
   char *cp4 = foo(dc);
 }
 
-int *foo(float _Complex) __attribute__((__overloadable__)); // expected-note 3 {{candidate function}}
+int *foo(float _Complex) __attribute__((__overloadable__));
 
 void test_foo_2(float fv, double dv, float _Complex fc, double _Complex dc) {
   char *cp1 = foo(fv);
-  char *cp2 = foo(dv); // expected-error{{call to 'foo' is ambiguous; candidates are:}}
+  char *cp2 = foo(dv);
   int *ip = foo(fc);
-  int *lp = foo(dc); // expected-error{{call to 'foo' is ambiguous; candidates are:}}
+  int *lp = foo(dc);
 }
 
-long *foo(double _Complex) __attribute__((__overloadable__)); // expected-note {{candidate function}}
+long *foo(double _Complex) __attribute__((__overloadable__));
 
 void test_foo_3(float fv, double dv, float _Complex fc, double _Complex dc) {
   char *cp1 = foo(fv);
-  char *cp2 = foo(dv); // expected-error{{call to 'foo' is ambiguous; candidates are:}}
+  char *cp2 = foo(dv);
   int *ip = foo(fc);
   long *lp = foo(dc);
 }

Modified: cfe/trunk/test/SemaCXX/complex-overload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/complex-overload.cpp?rev=97128&r1=97127&r2=97128&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/complex-overload.cpp (original)
+++ cfe/trunk/test/SemaCXX/complex-overload.cpp Thu Feb 25 01:20:54 2010
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-char *foo(float); // expected-note 3 {{candidate function}}
+char *foo(float);
 
 void test_foo_1(float fv, double dv, float _Complex fc, double _Complex dc) {
   char *cp1 = foo(fv);
@@ -9,20 +9,20 @@
   char *cp4 = foo(dc);
 }
 
-int *foo(float _Complex); // expected-note 3 {{candidate function}}
+int *foo(float _Complex);
 
 void test_foo_2(float fv, double dv, float _Complex fc, double _Complex dc) {
   char *cp1 = foo(fv);
-  char *cp2 = foo(dv); // expected-error{{call to 'foo' is ambiguous; candidates are:}}
+  char *cp2 = foo(dv);
   int *ip = foo(fc);
-  int *lp = foo(dc); // expected-error{{call to 'foo' is ambiguous; candidates are:}}
+  int *lp = foo(dc);
 }
 
-long *foo(double _Complex); // expected-note {{candidate function}}
+long *foo(double _Complex);
 
 void test_foo_3(float fv, double dv, float _Complex fc, double _Complex dc) {
   char *cp1 = foo(fv);
-  char *cp2 = foo(dv); // expected-error{{call to 'foo' is ambiguous; candidates are:}}
+  char *cp2 = foo(dv);
   int *ip = foo(fc);
   long *lp = foo(dc);
 }





More information about the cfe-commits mailing list