<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - No redeclared exception specification diagnostic for operator new at C++11"
   href="https://llvm.org/bugs/show_bug.cgi?id=26262">26262</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>No redeclared exception specification diagnostic for operator new at C++11
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>charles_li@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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() ;
      ^</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>