Reikriam

prefix-diff

Aug 9th, 2020 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
  2. index 6a3d2b30e46..7addedcf1a2 100644
  3. --- a/clang/lib/AST/TemplateBase.cpp
  4. +++ b/clang/lib/AST/TemplateBase.cpp
  5. @@ -70,13 +70,51 @@ static void printIntegral(const TemplateArgument &TemplArg,
  6.  
  7. if (T->isBooleanType() && !Policy.MSVCFormatting) {
  8. Out << (Val.getBoolValue() ? "true" : "false");
  9. + } else if (T->isBooleanType()) {
  10. + Out << Val;
  11. } else if (T->isCharType()) {
  12. const char Ch = Val.getZExtValue();
  13. Out << ((Ch == '\'') ? "'\\" : "'");
  14. Out.write_escaped(StringRef(&Ch, 1), /*UseHexEscapes=*/ true);
  15. Out << "'";
  16. } else {
  17. - Out << Val;
  18. + bool flag = false;
  19. + if (auto *autoT = T->getAs<AutoType>()) {
  20. + if (autoT->getAs<DeducedType>()) {
  21. + flag = true;
  22. + }
  23. + } else if (T->getAs<DeducedType>()) {
  24. + flag = true;
  25. + }
  26. + if (flag) {
  27. + if (auto *BT = T->getAs<BuiltinType>()) {
  28. + switch (BT->getKind()) {
  29. + case BuiltinType::ULongLong:
  30. + Out << Val << "ULL";
  31. + break;
  32. + case BuiltinType::LongLong:
  33. + Out << Val << "LL";
  34. + break;
  35. + case BuiltinType::ULong:
  36. + Out << Val << "UL";
  37. + break;
  38. + case BuiltinType::Long:
  39. + Out << Val << "L";
  40. + break;
  41. + case BuiltinType::UInt:
  42. + Out << Val << "U";
  43. + break;
  44. + case BuiltinType::Int:
  45. + Out << Val;
  46. + break;
  47. + default:
  48. + Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
  49. + << Val;
  50. + break;
  51. + }
  52. + }
  53. + } else
  54. + Out << Val;
  55. }
  56. }
  57.  
  58. diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
  59. index d63d307b9ab..13784148b0f 100644
  60. --- a/clang/lib/Sema/SemaTemplate.cpp
  61. +++ b/clang/lib/Sema/SemaTemplate.cpp
  62. @@ -6822,6 +6822,14 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
  63.  
  64. QualType CanonParamType = Context.getCanonicalType(ParamType);
  65.  
  66. + // Note: this renders CanonParamType non-canonical, but since every
  67. + // instantiation of this argument will be wrapped in an AutoType (since
  68. + // Param->getType() will always be an AutoType for this template), there
  69. + // should be no difference in how arguments are distinguished.
  70. + if (Param->getType()->getAs<AutoType>())
  71. + CanonParamType = Context.getAutoType(CanonParamType,
  72. + AutoTypeKeyword::Auto, false, false);
  73. +
  74. // Convert the APValue to a TemplateArgument.
  75. switch (Value.getKind()) {
  76. case APValue::None:
  77. diff --git a/clang/test/SemaTemplate/temp_arg_nontype.cpp b/clang/test/SemaTemplate/temp_arg_nontype.cpp
  78. index dd086dbb25b..d36178769f9 100644
  79. --- a/clang/test/SemaTemplate/temp_arg_nontype.cpp
  80. +++ b/clang/test/SemaTemplate/temp_arg_nontype.cpp
  81. @@ -270,6 +270,23 @@ namespace PR9227 {
  82. void test_char_possibly_negative() { enable_if_char<'\x02'>::type i; } // expected-error{{enable_if_char<'\x02'>'; did you mean 'enable_if_char<'a'>::type'?}}
  83. void test_char_single_quote() { enable_if_char<'\''>::type i; } // expected-error{{enable_if_char<'\''>'; did you mean 'enable_if_char<'a'>::type'?}}
  84. void test_char_backslash() { enable_if_char<'\\'>::type i; } // expected-error{{enable_if_char<'\\'>'; did you mean 'enable_if_char<'a'>::type'?}}
  85. +
  86. + template <int N> struct enable_if_int {};
  87. + template <> struct enable_if_int<1> { typedef int type; }; // expected-note{{'enable_if_int<1>::type' declared here}}
  88. + void test_int() { enable_if_int<2>::type i; } // expected-error{{enable_if_int<2>'; did you mean 'enable_if_int<1>::type'?}}
  89. +
  90. + template <unsigned int N> struct enable_if_unsigned_int {};
  91. + template <> struct enable_if_unsigned_int<1> { typedef int type; }; // expected-note{{'enable_if_unsigned_int<1>::type' declared here}}
  92. + void test_unsigned_int() { enable_if_unsigned_int<2>::type i; } // expected-error{{enable_if_unsigned_int<2>'; did you mean 'enable_if_unsigned_int<1>::type'?}}
  93. +
  94. + template <unsigned long long N> struct enable_if_unsigned_long_long {};
  95. + template <> struct enable_if_unsigned_long_long<1> { typedef int type; }; // expected-note{{'enable_if_unsigned_long_long<1>::type' declared here}}
  96. + void test_unsigned_long_long() { enable_if_unsigned_long_long<2>::type i; } // expected-error{{enable_if_unsigned_long_long<2>'; did you mean 'enable_if_unsigned_long_long<1>::type'?}}
  97. +
  98. + template <long long N> struct enable_if_long_long {};
  99. + template <> struct enable_if_long_long<1> { typedef int type; }; // expected-note{{'enable_if_long_long<1>::type' declared here}}
  100. + void test_long_long() { enable_if_long_long<2>::type i; } // expected-error{{enable_if_long_long<2>'; did you mean 'enable_if_long_long<1>::type'?}}
  101. +
  102. }
  103.  
  104. namespace PR10579 {
  105. diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  106. index 7538de33090..28fb89691fa 100644
  107. --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  108. +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  109. @@ -459,3 +459,13 @@ namespace PR46637 {
  110. X<f> y;
  111. int n = y.call(); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'void *'}}
  112. }
  113. +
  114. +namespace PR9227 {
  115. + template <auto N> struct S {};
  116. + template <> struct S<1> { using type = int; }; // expected-note {{'S<1>::type' declared here}}
  117. + S<1L>::type t; // expected-error {{no type named 'type' in 'PR9227::S<1L>'; did you mean 'S<1>::type'?}}
  118. +
  119. + template <auto N> struct A {};
  120. + template <> struct A<1> { using type = int; }; // expected-note {{'A<1>::type' declared here}}
  121. + A<2>::type x; // expected-error {{no type named 'type' in 'PR9227::A<2>'; did you mean 'A<1>::type'?}}
  122. +}
Advertisement
Add Comment
Please, Sign In to add comment