This is an archive of the discontinued LLVM Phabricator instance.

Lit C++11 Compatibility Patch #10
ClosedPublic

Authored by tigerleapgorge on Jun 22 2016, 3:41 PM.

Details

Summary

Hi Everyone,

I am continuing with updating the Lit tests for C++11 compatibility.
There are 5 tests.

test/Modules/Inputs/merge-using-decls/a.h
test/Modules/Inputs/merge-using-decls/b.h
test/Modules/merge-using-decls.cpp

This test verifies the interaction between Modules and Using declarations.
Part of this test, template struct “E” checks for mismatch between using declarations in a.h and Access declarations in b.h.
Since C++11 has deprecated Access declarations, module “B” will fail to build.
Therefore, I have restricted this part of the test to only use C++98.

test/SemaCXX/PR9572.cpp

This test verifies 2 types of diagnostics.

Type 1:
Warning for unsupported C++11 feature when compiling at C++98.
Guard the following Warning under C++98.
  C++98: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]

Type 2:
Errors when derived class inherit a private virtual destructor in the base class.
Class Base has a private virtual destructor.
Struct Foo inherits Base. Foo does not explicitly declare a destructor.
Struct Bar inherits Foo. Bar explicitly declares a destructor.
Struct Baz contains an instance of Foo as its member.
Because C++11 introduced ‘delete’, this results in the following changes in diagnostics.
C++98 issues 1 Error on Base’s private destructor.
C++11 issues 4 Errors at all points of the inheritance chain where the destructor is implicitly deleted.
  C++98: error: base class 'Base' has private destructor
         note: implicitly declared private here
         note: implicit destructor for 'Foo' first required here
  C++11: error: deleted function '~Foo' cannot override a non-deleted function
         note: overridden virtual function is here
  C++11: error: non-deleted function '~Bar' cannot override a deleted function
         note: overridden virtual function is here
  C++11: error: attempt to use a deleted function
         note: destructor of 'Foo' is implicitly deleted because base class 'Base' has an inaccessible destructor
  C++11: error: attempt to use a deleted function
         note: destructor of 'Foo' is implicitly deleted because base class 'Base' has an inaccessible destructor

test/SemaCXX/default-assignment-operator.cpp

C++11 introduced ‘delete’.
Change in diagnostics regarding implicitly deleted copy assignment operator. 
This test change contains 3 parts: Test1, Test5, ProtectedCheck.

Test1
  Class Base has a member “int &ref” that is never initialized.
  Class X is derived from Base. 
  Neither Base nor X explicitly declare their copy assignment operator.
  In C++98, Clang issues one error for each implicit class copy assignment operator definition failure (“Base” and “X”).
  In C++11, Clang issues one error for each assignment statement of the class instance. (“x = cx;” and “x = cx;”)
            And since there are 2 copy assignments of x, there are 2 sets of identical diagnostics in C++11.
    C++98: error: cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' cannot use copy assignment operator
           note: declared here
           note: implicit copy assignment operator for 'Base' first required here
           error: cannot define the implicit copy assignment operator for 'X', because non-static const member 'cint' cannot use copy assignment operator
           note: declared here
           note: implicit copy assignment operator for 'X' first required here
    C++11: error: object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted
           note: copy assignment operator of 'X' is implicitly deleted because base class 'Base' has a deleted copy assignment operator
           note: copy assignment operator of 'Base' is implicitly deleted because field 'ref' is of reference type 'int &'
           error: object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted
           note: copy assignment operator of 'X' is implicitly deleted because base class 'Base' has a deleted copy assignment operator
           note: copy assignment operator of 'Base' is implicitly deleted because field 'ref' is of reference type 'int &'

Test5
  Class E1 has a constant integer member ‘a’. E1 has a default constructor “E1() : a(0) {}”.
  Two instances of E1 are created, e1 and e2. e2 is assigned to e1.
  Change in diagnostics messages.
    C++98: error: cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' cannot use copy assignment operator
           note: declared here
           note: implicit copy assignment operator for 'E1' first required here
    C++11: error: object of type 'E1' cannot be assigned because its copy assignment operator is implicitly deleted
           note: copy assignment operator of 'E1' is implicitly deleted because field 'a' is of const-qualified type 'const int'

ProtectedCheck
  Class X has a protected copy assignment operator. 
  Struct Z contains an instance of X.
  An instance of Z, z, is copy assigned to itself (z = z).
  C++98 and C++11 issues different diagnostics.
    C++98: error: 'operator=' is a protected member of 'ProtectedCheck::X'
           note: declared protected here
           note: implicit copy assignment operator for 'ProtectedCheck::Z' first required here
    C++11: error: object of type 'ProtectedCheck::Z' cannot be assigned because its copy assignment operator is implicitly deleted
           note: copy assignment operator of 'Z' is implicitly deleted because field 'x' has an inaccessible copy assignment operator

test/SemaCXX/default-constructor-initializers.cpp

C++11 introduced ‘delete’.
As a result, implicitly deleted default constructor diagnostics changed.
http://en.cppreference.com/w/cpp/language/default_constructor


Part 1
X1 has no implicitly default constructor.
X2 inherits X1.
X3 inherits X2.
X3 is instantiated.
  C++98: error: implicit default constructor for 'X3' must explicitly initialize the base class 'X2' which does not have a default constructor
         note: 'X2' declared here
         note: implicit default constructor for 'X3' first required here
  C++11: error: call to implicitly-deleted default constructor of 'X3'
         note: default constructor of 'X3' is implicitly deleted because base class 'X2' has no default constructor

Part 2.
X4 contains an instance of X2 and a reference of X2.
C++98 issues 2 Errors, one for each member of the class.
C++11 issues 1 Error, for the instantiation of the class.
  C++98: error: implicit default constructor for 'X4' must explicitly initialize the member 'x2' which does not have a default constructor
         note: member is declared here
         note: 'X2' declared here
  C++98: error: implicit default constructor for 'X4' must explicitly initialize the reference member 'rx2'
         note: declared here
         note: implicit default constructor for 'X4' first required here
  C++11: error: call to implicitly-deleted default constructor of 'X4'
         note: default constructor of 'X4' is implicitly deleted because field 'x2' has no default constructor

Part 3.
Z1 has 3 members: integer reference z, constant integer c1 and volatile integer v1.
None of which are explicitly initialized.
Therefore, Z1 has no implicitly default constructor.
C++98 issues 2 Errors. One for the integer reference member. One for the constant integer member.
C++11 issues 1 Error for the instantiation of the class.
  C++98: error: implicit default constructor for 'Z1' must explicitly initialize the reference member 'z'
         note: declared here
         error: implicit default constructor for 'Z1' must explicitly initialize the const member 'c1'
         note: declared here
         note: implicit default constructor for 'Z1' first required here
  C++11: error: call to implicitly-deleted default constructor of 'Z1'
         note: default constructor of 'Z1' is implicitly deleted because field 'z' of reference type 'int &' would not be initialized

test/SemaCXX/warn-thread-safety-parsing.cpp

In C++11, does not issue Errors for thread safety attributes applied to static members.
http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
This may be a side effect of C++11’s relaxation on in-class member initializers.
http://www.stroustrup.com/C++11FAQ.html#member-init

Restrict the following diagnostics to C++98. (2 instances each)
  C++98: error: invalid use of non-static data member 'mu' 
  C++98: error: invalid use of member 'mu' in static member function

Diff Detail

Repository
rL LLVM

Event Timeline

tigerleapgorge retitled this revision from to Lit C++11 Compatibility Patch #10.
tigerleapgorge updated this object.
tigerleapgorge added a reviewer: rsmith.
tigerleapgorge added a subscriber: cfe-commits.

Update patch to match latest Clang C++11 diagnostics.

2 tests are changed.

test/SemaCXX/PR9572.cpp

Expect the following additional Note following existing Error.
  destructor of 'Foo' is implicitly deleted because base class 'Base' has an inaccessible destructor

test/SemaCXX/virtual-base-used.cpp

Expect the following additional Notes following existing Errors.
  destructor of 'B' is implicitly deleted because field 'x' has an inaccessible destructor
  destructor of 'E' is implicitly deleted because field 'x' has an inaccessible destructor
  destructor of 'H' is implicitly deleted because field 'x' has an inaccessible destructor

Previous update contain typos in the RUN lines of test/SemaCXX/virtual-base-used.cpp
This has been corrected in this latest revision.

Remove 2 tests reviewed under D29520.

tigerleapgorge edited the summary of this revision. (Show Details)Feb 6 2017, 2:54 PM
tigerleapgorge edited the summary of this revision. (Show Details)

Remove 2 OpenMP tests reviewed via D29725

tigerleapgorge edited the summary of this revision. (Show Details)

Remove 2 tests reviewed in D29685

rsmith accepted this revision.Feb 24 2017, 1:23 PM

LGTM with a couple of changes.

test/Modules/Inputs/merge-using-decls/a.h
25 ↗(On Diff #88232)

I don't see a reason to #ifdef this portion, which should work either way, and likewise for the other change to this file. (The changes to the other header and to the cpp file look fine and appropriate, though.)

test/SemaCXX/warn-thread-safety-parsing.cpp
1273 ↗(On Diff #88232)

Please add FIXMEs to this test. These cases are not supposed to be permitted.

This revision is now accepted and ready to land.Feb 24 2017, 1:23 PM

Updated patch in accordance to Richard Smith's comments.

tigerleapgorge marked 2 inline comments as done.Feb 24 2017, 3:33 PM
tigerleapgorge added inline comments.
test/SemaCXX/PR9572.cpp
34 ↗(On Diff #89736)

Clang added this note quite recently.

tigerleapgorge marked an inline comment as done.Feb 24 2017, 3:33 PM
This revision was automatically updated to reflect the committed changes.