mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-17 04:16:07 +00:00
Do not parse members of incomplete class.
If definition of a class is unknown and out-of-line definition of its member is encountered, do not parse the member declaration. This change fixes PR18542. Differential Revision: http://reviews.llvm.org/D8010 llvm-svn: 239483
This commit is contained in:
parent
c87a6faba1
commit
47ebb75cf9
@ -4663,12 +4663,14 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
|
|||||||
RequireCompleteDeclContext(D.getCXXScopeSpec(), DC))
|
RequireCompleteDeclContext(D.getCXXScopeSpec(), DC))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
// If a class is incomplete, do not parse entities inside it.
|
||||||
if (isa<CXXRecordDecl>(DC) && !cast<CXXRecordDecl>(DC)->hasDefinition()) {
|
if (isa<CXXRecordDecl>(DC) && !cast<CXXRecordDecl>(DC)->hasDefinition()) {
|
||||||
Diag(D.getIdentifierLoc(),
|
Diag(D.getIdentifierLoc(),
|
||||||
diag::err_member_def_undefined_record)
|
diag::err_member_def_undefined_record)
|
||||||
<< Name << DC << D.getCXXScopeSpec().getRange();
|
<< Name << DC << D.getCXXScopeSpec().getRange();
|
||||||
D.setInvalidType();
|
return nullptr;
|
||||||
} else if (!D.getDeclSpec().isFriendSpecified()) {
|
}
|
||||||
|
if (!D.getDeclSpec().isFriendSpecified()) {
|
||||||
if (diagnoseQualifiedDeclaration(D.getCXXScopeSpec(), DC,
|
if (diagnoseQualifiedDeclaration(D.getCXXScopeSpec(), DC,
|
||||||
Name, D.getIdentifierLoc())) {
|
Name, D.getIdentifierLoc())) {
|
||||||
if (DC->isRecord())
|
if (DC->isRecord())
|
||||||
|
@ -47,3 +47,15 @@ struct C; // expected-note{{forward declaration}}
|
|||||||
void test_incomplete_object_call(C& c) {
|
void test_incomplete_object_call(C& c) {
|
||||||
c(); // expected-error{{incomplete type in call to object of type}}
|
c(); // expected-error{{incomplete type in call to object of type}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace pr18542 {
|
||||||
|
struct X {
|
||||||
|
int count;
|
||||||
|
template<typename CharT> class basic_istream;
|
||||||
|
template<typename CharT>
|
||||||
|
void basic_istream<CharT>::read() { // expected-error{{out-of-line definition of 'read' from class 'basic_istream<CharT>' without definition}}
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user