diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2016-06-09 05:26:56 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2016-06-09 05:26:56 +0000 |
| commit | 76a256260ed066d02b548c768d3c175f4902f484 (patch) | |
| tree | 1a1f5469a06fe39a43557bd4942c27771dcdd509 /clang | |
| parent | 2769bb5753618eabe700b223212c304aefc70d34 (diff) | |
| download | bcm5719-llvm-76a256260ed066d02b548c768d3c175f4902f484.tar.gz bcm5719-llvm-76a256260ed066d02b548c768d3c175f4902f484.zip | |
[Sema] Don't crash when a field w/ a mem-initializer clashes with a record name
It is possible for a field and a class to have the same name. In such
cases, performing lookup for the field might return a result set with
more than one entry. An overzealous assertion fired, causing us to
crash instead of using the non-class lookup result.
This fixes PR28060.
llvm-svn: 272247
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 3 | ||||
| -rw-r--r-- | clang/test/SemaCXX/member-init.cpp | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 554d1abbed1..24a47d19421 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2637,8 +2637,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, Instantiation->getTemplateInstantiationPattern(); DeclContext::lookup_result Lookup = ClassPattern->lookup(Field->getDeclName()); - assert(Lookup.size() == 1); - FieldDecl *Pattern = cast<FieldDecl>(Lookup[0]); + FieldDecl *Pattern = cast<FieldDecl>(Lookup.front()); InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, TemplateArgs); } diff --git a/clang/test/SemaCXX/member-init.cpp b/clang/test/SemaCXX/member-init.cpp index b3ee30b456e..65c8873117a 100644 --- a/clang/test/SemaCXX/member-init.cpp +++ b/clang/test/SemaCXX/member-init.cpp @@ -192,3 +192,13 @@ struct S { int x[3] = {[N] = 3}; }; } + +namespace PR28060 { +template <class T> +void foo(T v) { + struct s { + T *s = 0; + }; +} +template void foo(int); +} |

