[llvm-bugs] [Bug 26262] New: No redeclared exception specification diagnostic for operator new at C++11

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 22 14:05:48 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26262

            Bug ID: 26262
           Summary: No redeclared exception specification diagnostic for
                    operator new at C++11
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: charles_li at playstation.sony.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

This bug has been discovered while updating Lit test 
CXX/basic/basic.stc/basic.stc.dynamic/p2.cpp for C++11 compatibility.

The gist of the bug is that when an operator is declared with a throw() then 
redeclared without one, the compiler should issue a diagnostic regardless of
operator.

As we shall see in the test case below, 
a diagnostic was issues in every case except for operator new at C++11.

Here is the reduced test case.
/****************************************************/
namespace std {
  class bad_alloc { };
  typedef __SIZE_TYPE__ size_t;
}

void* operator new(std::size_t) throw(std::bad_alloc);
void* operator new(std::size_t);

void operator delete(void*)  throw() ;
void operator delete(void*);
/****************************************************/

In C++98, Clang will issue warnings on both the re-decleration of operator new
and operator delete.

$ clang -c nd.cpp -std=c++98 -Wall -fexceptions -frtti
nd.cpp:7:7: warning: 'operator new' is missing exception specification
'throw(std::bad_alloc)'
void* operator new(std::size_t);
      ^
                                throw(std::bad_alloc)
nd.cpp:6:7: note: previous declaration is here
void* operator new(std::size_t) throw(std::bad_alloc);
      ^
nd.cpp:10:6: warning: 'operator delete' is missing exception specification
'throw()'
void operator delete(void*);
     ^
                            throw()
nd.cpp:9:6: note: previous declaration is here
void operator delete(void*)  throw() ;
     ^
2 warnings generated.


In C++11, Clang will only issue a warning on the delete operator.

$ cl -c nd.cpp -std=c++11 -Wall -fexceptions -frtti
nd.cpp:10:6: warning: function previously declared with 
an explicit exception specification redeclared with 
an implicit exception specification [-Wimplicit-exception-spec-mismatch]
void operator delete(void*);
     ^
nd.cpp:9:6: note: previous declaration is here
void operator delete(void*)  throw() ;
     ^
1 warning generated.


For comparison, GCC (version 4.9.2) issues diagnostics for both 
operator new and operator delete at C++98 and C++11

$ gcc -c nd.cpp -std=c++98 -Wall -fexceptions -frtti
nd.cpp:7:31: error: declaration of ‘void* operator new(std::size_t)’ has a
different exception specifier
void* operator new(std::size_t);
                               ^
nd.cpp:6:7: error: from previous declaration ‘void* operator new(std::size_t)
throw (std::bad_alloc)’
void* operator new(std::size_t) throw(std::bad_alloc);
       ^
nd.cpp:10:27: error: declaration of ‘void operator delete(void*)’ has a
different exception specifier
void operator delete(void*);
                           ^
nd.cpp:9:6: error: from previous declaration ‘void operator delete(void*) throw
()’
void operator delete(void*)  throw() ;
      ^

$ gcc -c nd.cpp -std=c++11 -Wall -fexceptions -frtti
nd.cpp:7:31: error: declaration of ‘void* operator new(std::size_t)’ has a
different exception specifier
void* operator new(std::size_t);
                               ^
nd.cpp:6:7: error: from previous declaration ‘void* operator new(std::size_t)
throw (std::bad_alloc)’
void* operator new(std::size_t) throw(std::bad_alloc);
       ^
nd.cpp:10:27: error: declaration of ‘void operator delete(void*)’ has a
different exception specifier
void operator delete(void*);
                           ^
nd.cpp:9:6: error: from previous declaration ‘void operator delete(void*) throw
()’
void operator delete(void*)  throw() ;
      ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160122/789658a5/attachment.html>


More information about the llvm-bugs mailing list