Bug 49332

Summary: [C++11/14 only] noexcept ignored on function pointer
Product: gcc Reporter: Jason Merrill <jason>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: ai.azuma, egallager, fang, fchelnokov, jason, mpolacek, webrown.cpp
Priority: P3 Keywords: accepts-invalid, rejects-valid
Version: 4.7.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2011-06-08 21:47:18
Bug Depends on: 12255    
Bug Blocks:    

Description Jason Merrill 2011-06-08 21:45:39 UTC
This testcase should give an error on the initialization and no error on the static_assert.

// { dg-options -std=c++0x }                                                                   

void f();
void (*p)() noexcept = f; // { dg-error "" }                                             

#define SA(X) static_assert((X),#X)

SA(noexcept(p()));

The underlying issue is PR 12255, but while this behavior was not observable in C++98, it is observable in C++0x.
Comment 1 Jason Merrill 2011-06-08 21:47:04 UTC
Or rather in C++98 it was observable through diagnostics, but couldn't change the behavior of a well-defined program.
Comment 2 Marek Polacek 2019-06-21 16:53:37 UTC
This still compiles without errors in C++11, but in C++17:

49332.C:4:24: error: invalid conversion from ‘void (*)()’ to ‘void (*)() noexcept’ [-fpermissive]
    4 | void (*p)() noexcept = f; // { dg-error "" }
      |                        ^
      |                        |
      |                        void (*)()
Comment 3 Andrew Pinski 2021-11-06 04:55:26 UTC
*** Bug 103092 has been marked as a duplicate of this bug. ***