This is an archive of the discontinued LLVM Phabricator instance.

Do not parse members of incomplete class.
ClosedPublic

Authored by sepavloff on Mar 2 2015, 9:54 AM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

sepavloff updated this revision to Diff 21015.Mar 2 2015, 9:54 AM
sepavloff retitled this revision from to Do not parse members of incomplete class..
sepavloff updated this object.
sepavloff edited the test plan for this revision. (Show Details)
sepavloff added a subscriber: Unknown Object (MLST).

Any feedback?

Thanks,
--Serge

2015-03-02 23:54 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

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.

http://reviews.llvm.org/D8010

Files:

lib/Sema/SemaDecl.cpp
test/SemaCXX/incomplete-call.cpp

Index: lib/Sema/SemaDecl.cpp

  • lib/Sema/SemaDecl.cpp

+++ lib/Sema/SemaDecl.cpp
@@ -4573,12 +4573,14 @@

  RequireCompleteDeclContext(D.getCXXScopeSpec(), DC))
return nullptr;

+ // If a class is incomplete, do not parse entities inside it.

if (isa<CXXRecordDecl>(DC) &&

!cast<CXXRecordDecl>(DC)->hasDefinition()) {

Diag(D.getIdentifierLoc(),
     diag::err_member_def_undefined_record)
  << Name << DC << D.getCXXScopeSpec().getRange();
  • D.setInvalidType();
  • } else if (!D.getDeclSpec().isFriendSpecified()) {

+ return nullptr;
+ }
+ if (!D.getDeclSpec().isFriendSpecified()) {

if (diagnoseQualifiedDeclaration(D.getCXXScopeSpec(), DC,
                                Name, D.getIdentifierLoc())) {
  if (DC->isRecord())

Index: test/SemaCXX/incomplete-call.cpp

  • test/SemaCXX/incomplete-call.cpp

+++ test/SemaCXX/incomplete-call.cpp
@@ -47,3 +47,15 @@
void test_incomplete_object_call(C& c) {

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;
+ }
+ };
+}
+

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/

Ping.

Thanks,
--Serge

2015-03-12 23:30 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Any feedback?

Thanks,
--Serge

2015-03-02 23:54 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

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.

http://reviews.llvm.org/D8010

Files:

lib/Sema/SemaDecl.cpp
test/SemaCXX/incomplete-call.cpp

Index: lib/Sema/SemaDecl.cpp

  • lib/Sema/SemaDecl.cpp

+++ lib/Sema/SemaDecl.cpp
@@ -4573,12 +4573,14 @@

  RequireCompleteDeclContext(D.getCXXScopeSpec(), DC))
return nullptr;

+ // If a class is incomplete, do not parse entities inside it.

if (isa<CXXRecordDecl>(DC) &&

!cast<CXXRecordDecl>(DC)->hasDefinition()) {

Diag(D.getIdentifierLoc(),
     diag::err_member_def_undefined_record)
  << Name << DC << D.getCXXScopeSpec().getRange();
  • D.setInvalidType();
  • } else if (!D.getDeclSpec().isFriendSpecified()) {

+ return nullptr;
+ }
+ if (!D.getDeclSpec().isFriendSpecified()) {

if (diagnoseQualifiedDeclaration(D.getCXXScopeSpec(), DC,
                                Name, D.getIdentifierLoc())) {
  if (DC->isRecord())

Index: test/SemaCXX/incomplete-call.cpp

  • test/SemaCXX/incomplete-call.cpp

+++ test/SemaCXX/incomplete-call.cpp
@@ -47,3 +47,15 @@
void test_incomplete_object_call(C& c) {

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;
+ }
+ };
+}
+

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/

Ping.

Thanks,
--Serge

2015-03-19 10:22 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Ping.

Thanks,
--Serge

2015-03-12 23:30 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Any feedback?

Thanks,
--Serge

2015-03-02 23:54 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

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.

http://reviews.llvm.org/D8010

Files:

lib/Sema/SemaDecl.cpp
test/SemaCXX/incomplete-call.cpp

Index: lib/Sema/SemaDecl.cpp

  • lib/Sema/SemaDecl.cpp

+++ lib/Sema/SemaDecl.cpp
@@ -4573,12 +4573,14 @@

  RequireCompleteDeclContext(D.getCXXScopeSpec(), DC))
return nullptr;

+ // If a class is incomplete, do not parse entities inside it.

if (isa<CXXRecordDecl>(DC) &&

!cast<CXXRecordDecl>(DC)->hasDefinition()) {

Diag(D.getIdentifierLoc(),
     diag::err_member_def_undefined_record)
  << Name << DC << D.getCXXScopeSpec().getRange();
  • D.setInvalidType();
  • } else if (!D.getDeclSpec().isFriendSpecified()) {

+ return nullptr;
+ }
+ if (!D.getDeclSpec().isFriendSpecified()) {

if (diagnoseQualifiedDeclaration(D.getCXXScopeSpec(), DC,
                                Name, D.getIdentifierLoc())) {
  if (DC->isRecord())

Index: test/SemaCXX/incomplete-call.cpp

  • test/SemaCXX/incomplete-call.cpp

+++ test/SemaCXX/incomplete-call.cpp
@@ -47,3 +47,15 @@
void test_incomplete_object_call(C& c) {

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;
+ }
+ };
+}
+

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/

Any feedback?

Thanks,
--Serge

2015-04-16 0:52 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Ping.

Thanks,
--Serge

2015-03-19 10:22 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Ping.

Thanks,
--Serge

2015-03-12 23:30 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Any feedback?

Thanks,
--Serge

2015-03-02 23:54 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

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.

http://reviews.llvm.org/D8010

Files:

lib/Sema/SemaDecl.cpp
test/SemaCXX/incomplete-call.cpp

Index: lib/Sema/SemaDecl.cpp

  • lib/Sema/SemaDecl.cpp

+++ lib/Sema/SemaDecl.cpp
@@ -4573,12 +4573,14 @@

  RequireCompleteDeclContext(D.getCXXScopeSpec(), DC))
return nullptr;

+ // If a class is incomplete, do not parse entities inside it.

if (isa<CXXRecordDecl>(DC) &&

!cast<CXXRecordDecl>(DC)->hasDefinition()) {

Diag(D.getIdentifierLoc(),
     diag::err_member_def_undefined_record)
  << Name << DC << D.getCXXScopeSpec().getRange();
  • D.setInvalidType();
  • } else if (!D.getDeclSpec().isFriendSpecified()) {

+ return nullptr;
+ }
+ if (!D.getDeclSpec().isFriendSpecified()) {

if (diagnoseQualifiedDeclaration(D.getCXXScopeSpec(), DC,
                                Name, D.getIdentifierLoc())) {
  if (DC->isRecord())

Index: test/SemaCXX/incomplete-call.cpp

  • test/SemaCXX/incomplete-call.cpp

+++ test/SemaCXX/incomplete-call.cpp
@@ -47,3 +47,15 @@
void test_incomplete_object_call(C& c) {

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;
+ }
+ };
+}
+

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/

Ping!

Thanks,
--Serge

2015-05-25 18:15 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Any feedback?

Thanks,
--Serge

2015-04-16 0:52 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Ping.

Thanks,
--Serge

2015-03-19 10:22 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Ping.

Thanks,
--Serge

2015-03-12 23:30 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

Any feedback?

Thanks,
--Serge

2015-03-02 23:54 GMT+06:00 Serge Pavlov <sepavloff@gmail.com>:

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.

http://reviews.llvm.org/D8010

Files:

lib/Sema/SemaDecl.cpp
test/SemaCXX/incomplete-call.cpp

Index: lib/Sema/SemaDecl.cpp

  • lib/Sema/SemaDecl.cpp

+++ lib/Sema/SemaDecl.cpp
@@ -4573,12 +4573,14 @@

  RequireCompleteDeclContext(D.getCXXScopeSpec(), DC))
return nullptr;

+ // If a class is incomplete, do not parse entities inside it.

if (isa<CXXRecordDecl>(DC) &&

!cast<CXXRecordDecl>(DC)->hasDefinition()) {

Diag(D.getIdentifierLoc(),
     diag::err_member_def_undefined_record)
  << Name << DC << D.getCXXScopeSpec().getRange();
  • D.setInvalidType();
  • } else if (!D.getDeclSpec().isFriendSpecified()) {

+ return nullptr;
+ }
+ if (!D.getDeclSpec().isFriendSpecified()) {

if (diagnoseQualifiedDeclaration(D.getCXXScopeSpec(), DC,
                                Name, D.getIdentifierLoc())) {
  if (DC->isRecord())

Index: test/SemaCXX/incomplete-call.cpp

  • test/SemaCXX/incomplete-call.cpp

+++ test/SemaCXX/incomplete-call.cpp
@@ -47,3 +47,15 @@
void test_incomplete_object_call(C& c) {

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;
+ }
+ };
+}
+

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/
rsmith accepted this revision.Jun 9 2015, 2:05 PM
rsmith added a reviewer: rsmith.
rsmith added a subscriber: rsmith.

LGTM

This revision is now accepted and ready to land.Jun 9 2015, 2:05 PM
This revision was automatically updated to reflect the committed changes.