Shafik Yaghmour 6ec446ddce [Clang] Add sanity check in Sema::getDestructorName to prevent nullptr dereference
Currently in Sema::getDestructorName we call SS.getScopeRep()->getPrefix() but
SS.getScopeRep() can return nullptr because LookupInNestedNameSpec(...) called a
little before can invalidate SS.

This fixes: https://github.com/llvm/llvm-project/issues/59446

Differential Revision: https://reviews.llvm.org/D140598
2023-01-25 10:49:04 -08:00

13 lines
739 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
namespace GH59446 { // expected-note {{to match this '{'}}
namespace N {
template <typename T> struct X ; // expected-note 2 {{template is declared here}}
// expected-note@-1 {{'N::X' declared here}}
// expected-note@-2 {{non-type declaration found by destructor name lookup}}
}
void f(X<int> *x) { // expected-error {{no template named 'X'; did you mean 'N::X'}}
x->N::X<int>::~X(); // expected-error 2 {{implicit instantiation of undefined template 'GH59446::N::X<int>'}}
// expected-error@-1 {{identifier 'X' after '~' in destructor name does not name a type}}
} // expected-error {{expected '}'}}