Re: r272247 - [Sema] Don't crash when a field w/ a mem-initializer clashes with a record name
On Thu, Jun 9, 2016 at 4:51 PM, David Majnemerwrote: > It would mean that the instantiation of the class template gained a field > which should be impossible. OK, so assert(Lookup.size() > 0) always holds? Makes sense, thanks. - Kim ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r272247 - [Sema] Don't crash when a field w/ a mem-initializer clashes with a record name
It would mean that the instantiation of the class template gained a field which should be impossible. On Thursday, June 9, 2016, Kim Gräsmanwrote: > On Thu, Jun 9, 2016 at 7:26 AM, David Majnemer via cfe-commits > > wrote: > > Author: majnemer > > Date: Thu Jun 9 00:26:56 2016 > > New Revision: 272247 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=272247=rev > > Log: > > [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. > > > > Modified: > > cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp > > cfe/trunk/test/SemaCXX/member-init.cpp > > > > Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=272247=272246=272247=diff > > > == > > --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) > > +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Jun 9 00:26:56 > 2016 > > @@ -2637,8 +2637,7 @@ Sema::InstantiateClassMembers(SourceLoca > > Instantiation->getTemplateInstantiationPattern(); > > DeclContext::lookup_result Lookup = > > ClassPattern->lookup(Field->getDeclName()); > > -assert(Lookup.size() == 1); > > -FieldDecl *Pattern = cast(Lookup[0]); > > +FieldDecl *Pattern = cast(Lookup.front()); > > InstantiateInClassInitializer(PointOfInstantiation, Field, > Pattern, > >TemplateArgs); > >} > > Now what if there is no match? Or is that guaranteed (given the prior > assert)? > > - Kim > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r272247 - [Sema] Don't crash when a field w/ a mem-initializer clashes with a record name
On Thu, Jun 9, 2016 at 7:26 AM, David Majnemer via cfe-commitswrote: > Author: majnemer > Date: Thu Jun 9 00:26:56 2016 > New Revision: 272247 > > URL: http://llvm.org/viewvc/llvm-project?rev=272247=rev > Log: > [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. > > Modified: > cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp > cfe/trunk/test/SemaCXX/member-init.cpp > > Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=272247=272246=272247=diff > == > --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) > +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Jun 9 00:26:56 2016 > @@ -2637,8 +2637,7 @@ Sema::InstantiateClassMembers(SourceLoca > Instantiation->getTemplateInstantiationPattern(); > DeclContext::lookup_result Lookup = > ClassPattern->lookup(Field->getDeclName()); > -assert(Lookup.size() == 1); > -FieldDecl *Pattern = cast(Lookup[0]); > +FieldDecl *Pattern = cast(Lookup.front()); > InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, >TemplateArgs); >} Now what if there is no match? Or is that guaranteed (given the prior assert)? - Kim ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r272247 - [Sema] Don't crash when a field w/ a mem-initializer clashes with a record name
Author: majnemer Date: Thu Jun 9 00:26:56 2016 New Revision: 272247 URL: http://llvm.org/viewvc/llvm-project?rev=272247=rev Log: [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. Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp cfe/trunk/test/SemaCXX/member-init.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=272247=272246=272247=diff == --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Jun 9 00:26:56 2016 @@ -2637,8 +2637,7 @@ Sema::InstantiateClassMembers(SourceLoca Instantiation->getTemplateInstantiationPattern(); DeclContext::lookup_result Lookup = ClassPattern->lookup(Field->getDeclName()); -assert(Lookup.size() == 1); -FieldDecl *Pattern = cast(Lookup[0]); +FieldDecl *Pattern = cast(Lookup.front()); InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, TemplateArgs); } Modified: cfe/trunk/test/SemaCXX/member-init.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-init.cpp?rev=272247=272246=272247=diff == --- cfe/trunk/test/SemaCXX/member-init.cpp (original) +++ cfe/trunk/test/SemaCXX/member-init.cpp Thu Jun 9 00:26:56 2016 @@ -192,3 +192,13 @@ struct S { int x[3] = {[N] = 3}; }; } + +namespace PR28060 { +template +void foo(T v) { + struct s { +T *s = 0; + }; +} +template void foo(int); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits