]> granicus.if.org Git - clang/commitdiff
Properly handle non-canonical underlying types in
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 5 Mar 2012 16:02:06 +0000 (16:02 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 5 Mar 2012 16:02:06 +0000 (16:02 +0000)
ASTContext::getUnaryTransformType.  This can happen if, for example,
an enumeration's underlying type is a typedef.

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

lib/AST/ASTContext.cpp
test/SemaCXX/underlying_type.cpp

index 9424bc3006f3e02d69232c007fa50ae91609e734..5122c21c9adedbfd42877ca498967ab863dac746 100644 (file)
@@ -2962,7 +2962,7 @@ QualType ASTContext::getUnaryTransformType(QualType BaseType,
     new (*this, TypeAlignment) UnaryTransformType (BaseType, UnderlyingType, 
                                                    Kind,
                                  UnderlyingType->isDependentType() ?
-                                    QualType() : UnderlyingType);
+                                 QualType() : getCanonicalType(UnderlyingType));
   Types.push_back(Ty);
   return QualType(Ty, 0);
 }
index dcfaab3c8b4da169248d46a644c0559882df4d97..7bca06bf074e566f2310b32acc86ee511504539c 100644 (file)
@@ -35,3 +35,9 @@ static_assert(is_same_type<underlying_type<f>::type, char>::value,
               "f has the wrong underlying type in the template");
 
 underlying_type<int>::type e; // expected-note {{requested here}}
+
+using uint = unsigned;
+enum class foo : uint { bar };
+static_assert(is_same_type<underlying_type<foo>::type, unsigned>::value,
+              "foo has the wrong underlying type");