This is an archive of the discontinued LLVM Phabricator instance.

Lit C++11 Compatibility - Microsoft diagnostics
ClosedPublic

Authored by tigerleapgorge on Feb 3 2017, 3:20 PM.

Details

Summary

I am continuing to make Lit tests C++11 compatible.
This patch contains 4 tests, previously in review D20710 and D21626.

test/SemaCXX/MicrosoftExtensions.cpp

This test checks for Microsoft extensions.
Portions of this test check for unsupported C++11 features when compiling at C++98.
Guard all such diagnostics under C++98.

Base destructor being marked with “throw()”, derived destructor is not.
This no longer results in the following diagnostics in C++11.
  C++98: warning: exception specification of overriding function is more lax than base version [-Wmicrosoft-exception-spec]
         note: overridden virtual function is here

Enum with underlying type is now supported in C++11. Guard the following under C++98.
  C++98: warning: enumeration types with a fixed underlying type are a C++11 extension [-Wc++11-extensions]
  C++98: warning: enumeration types with a fixed underlying type are a C++11 extension [-Wc++11-extensions]

“override” is now supported in C++11. Guard the following under C++98.
  C++98: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]

test/SemaCXX/implicit-virtual-member-functions.cpp

Change in diagnostics (3 instances)
  C++98: error: no suitable member 'operator delete' in 'B'
         note: member 'operator delete' declared here
         note: implicit destructor for 'B' first required here
  C++11: error: deleted function '~B' cannot override a non-deleted function
         note: overridden virtual function is here

Added diagnostics in C++11 when target is Microsoft.
  C++11: error: attempt to use a deleted function
         note: virtual destructor requires an unambiguous, accessible 
               'operator delete'

test/SemaCXX/virtual-base-used.cpp

The base class explicitly declares a public virtual destructor.
The derived class does not explicitly declare a destructor.
The derived class contains a member with an inaccessible private destructor.
In C++98, Clang Warns about the private destructor then gives a Note at class instantiation (MSABI) or class method definition.
In C++11, The derived class having a member that can not be destroyed means the derived class’s own implicit destructor is deleted.
          Therefore, Clang issues an Error on the derived class’s deleted destructor trying to overwrite base class’s non-deleted destructor.
          Furthermore, Clang also issues Errors on classes further down the inheritance chain with explicitly declared destructors trying to 
          overwrite first derived class’s implicitly deleted destructor.

This test is subdivided into three sections. Each section has its own inheritance chain.

Section 1:
 A is the base struct with a virtual destructor.
 B derives from A. B has a member class instance ‘x’ with an inaccessible destructor.
 D derives from B. D has an explicitly declared destructor.
 In C++98, Clang issues an Error about B’s x having no accessible destructor.
  In C++11, Clang issues 2 Errors.
            First Error on B’s implicitly deleted destructor inheriting A’s explicitly declared destructor.
            Second Error on D’s explicitly declared destructor inheriting B’s implicitly deleted destructor.

  C++98: error: field of type 'NoDestroy' has private destructor
         note: implicitly declared private here
         note: implicit destructor for 'B' first required here
  C++11: error: deleted function '~B' cannot override a non-deleted function
         note: overridden virtual function is here
         error: non-deleted function '~D' cannot override a deleted function
         note: overridden virtual function is here

Section 2:
  A is the base struct with a virtual destructor.
  E derives A. E also has a member class instance x with no destructor.
  F derives from E and has no explicitly declared destructor.
  G derives from F and has an explicitly declared destructor.
  In C++98, Clang issues an Error about E’s x having no accessible destructor.
  In C++11, Clang issues 3 Errors.
            First Error about E’s implicitly deleted destructor inheriting A’s explicitly declared destructor.
            Second Error about F’s implicitly declared destructor inheriting E’s implicitly deleted destructor.
            Third Error about G’s explicitly declared destructor inheriting F’s now implicitly deleted destructor.

  C++98: error: field of type 'NoDestroy' has private destructor
         note: implicitly declared private here
         note: implicit destructor for 'E' first required here
  C++11: error: deleted function '~E' cannot override a non-deleted function
         note: overridden virtual function is here
         error: non-deleted function '~F' cannot override a deleted function
         note: overridden virtual function is here
         error: non-deleted function '~G' cannot override a deleted function
         note: overridden virtual function is here


Section 3:
  A is a struct with a virtual destructor.
  H derives from A. H has a member x with an inaccessible destructor.
  I derives from H.
  J derives from I. J has a member function foo() definition.
  In C++98, Clang issues an error on the H’s member X having an private destructor.
  In C++11, Clang issues 2 errors. 
            First  Error on H’s implicitly deleted destructor inheriting A’s explicitly declared destructor.
            Second Error on I’s explicitly declared destructor inheriting H’s implicitly deleted destructor.

  C++98: error: field of type 'NoDestroy' has private destructor
         note: implicitly declared private here
         note: implicit destructor for 'H' first required here
  C++11: error: deleted function '~H' cannot override a non-deleted function
         note: overridden virtual function is here
         error: non-deleted function '~I' cannot override a deleted function
         note: overridden virtual function is here

test/SemaTemplate/virtual-member-functions.cpp

Change in diagnostics when derived class inherits a private destructor
in the base class.

C++98: error: base class 'PR7114::A' has private destructor
       note: implicitly declared private here
       note: implicit destructor for 'PR7114::B<float>::Inner' first required here

C++11: error: deleted function '~Inner' cannot override a non-deleted function
       note: in instantiation of member class 'PR7114::B<int>::Inner' requested here
       note: in instantiation of template class 'PR7114::B<int>' requested here
       note: overridden virtual function is here

       error: deleted function '~Inner' cannot override a non-deleted function
       note: in instantiation of member class 'PR7114::B<float>::Inner' requested here
       note: in instantiation of template class 'PR7114::B<float>' requested here
       note: overridden virtual function is here

       error: deleted function '~X' cannot override a non-deleted function
       note: in instantiation of template class 'PR7114::X<int>' requested here
       note: overridden virtual function is here

Diff Detail

Repository
rL LLVM

Event Timeline

tigerleapgorge created this revision.Feb 3 2017, 3:20 PM
rnk accepted this revision.Feb 6 2017, 10:40 AM

lgtm

This revision is now accepted and ready to land.Feb 6 2017, 10:40 AM
This revision was automatically updated to reflect the committed changes.