Following patch fixes crash in clang with attached test case [taken from g++.old-deja/g++.other/using3.C].
Issue:
Test is trying to make using declaration for a non-existing member in base class in derived class and expect error
while compiling. Current clang code handles normal cases properly.
Problem arises when base class is typedefed to a type constructed in-place. As using declaration is referring to a
non-existing member, normal lookup fails and while trying typo-correction, clang returns typedef declaration as
possible alternative, which is not a record type and can not be type casted to EnumDecl/ RecordDecl/ CXXRecordDecl.
But Sema::CheckUsingShadowDecl() assumes otherwise and tries to typecast it to CXXRecordDecl without any check
while checking if referred type is from base class or not. This results in crash in clang.
Solution:
I looked for ways to get CXXRecordDecl from TypedefDecl but did not find any. I found function like getUnderlyingDecl()
but they just work with UsingDecls and ObjCCompatibleAliasDecls. Moreover, for any existing member, clang find proper
declaration and everything works fine.
So I have added a check in Sema::CheckUsingShadowDecl() to bypass base class check if referred type in using declaration
is not in a record type. A proper fix may be if we can get proper RecordDecl from TypedefDecl and use it for this check
or handle TypedefDecl case separately.
Is this still necessary?