summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-07-24 05:54:19 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-07-24 05:54:19 +0000
commit16a74704c9e7cebcdba819befa5dfab75fab9259 (patch)
tree977aca7f29826127668034ee01376e54db984e6f
parentb7d8563973fe5970509d526c73697feb1081c4c2 (diff)
downloadbcm5719-llvm-16a74704c9e7cebcdba819befa5dfab75fab9259.tar.gz
bcm5719-llvm-16a74704c9e7cebcdba819befa5dfab75fab9259.zip
[AST] Perform additional canonicalization for DependentSizedArrayType
We treated DependentSizedArrayTypes with the same element type but differing size expressions as equivalently canonical. This would lead to bizarre behavior during template instantiation. This fixes PR24212. llvm-svn: 243093
-rw-r--r--clang/lib/AST/ASTContext.cpp7
-rw-r--r--clang/test/SemaCXX/alias-template.cpp11
2 files changed, 15 insertions, 3 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 61bd1077941..ba4bcbc488c 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2759,9 +2759,10 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType,
QualType canon = getQualifiedType(QualType(canonTy,0),
canonElementType.Quals);
- // If we didn't need extra canonicalization for the element type,
- // then just use that as our result.
- if (QualType(canonElementType.Ty, 0) == elementType)
+ // If we didn't need extra canonicalization for the element type or the size
+ // expression, then just use that as our result.
+ if (QualType(canonElementType.Ty, 0) == elementType &&
+ canonTy->getSizeExpr() == numElements)
return canon;
// Otherwise, we need to build a type which follows the spelling
diff --git a/clang/test/SemaCXX/alias-template.cpp b/clang/test/SemaCXX/alias-template.cpp
index d5eb27a6613..bcfe428c69d 100644
--- a/clang/test/SemaCXX/alias-template.cpp
+++ b/clang/test/SemaCXX/alias-template.cpp
@@ -168,3 +168,14 @@ namespace SFINAE {
fail1<int> f1; // expected-note {{here}}
fail2<E> f2; // expected-note {{here}}
}
+
+namespace PR24212 {
+struct X {};
+template <int I>
+struct S {
+ template <int J>
+ using T = X[J];
+ using U = T<I>;
+};
+static_assert(__is_same(S<3>::U, X[2]), ""); // expected-error {{static_assert failed}}
+}
OpenPOWER on IntegriCloud