Skip to content

Commit

Permalink
[clang] Add test for CWG2486 (noexcept and function pointer convers…
Browse files Browse the repository at this point in the history
…ion) (llvm#107131)

[CWG2486](https://cplusplus.github.io/CWG/issues/2486.html) "Call to
`noexcept` function via `noexcept(false)` pointer/lvalue" allows
`noexcept` functions to be called via `noexcept(false)` pointers or
values. There appears to be no implementation divergence whatsoever:
https://godbolt.org/z/3afTfeEM8. That said, in C++14 and earlier we do
not issue all the diagnostics we issue in C++17 and newer, so I'm
specifying the status of the issue accordingly.
  • Loading branch information
Endilll committed Sep 4, 2024
1 parent 3e8840b commit eaa95a1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
43 changes: 36 additions & 7 deletions clang/test/CXX/drs/cwg24xx.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// RUN: %clang_cc1 -std=c++98 -pedantic-errors %s -verify=expected
// RUN: %clang_cc1 -std=c++11 -pedantic-errors %s -verify=expected
// RUN: %clang_cc1 -std=c++14 -pedantic-errors %s -verify=expected
// RUN: %clang_cc1 -std=c++98 -pedantic-errors %s -verify=expected,cxx98-14
// RUN: %clang_cc1 -std=c++11 -pedantic-errors %s -verify=expected,cxx98-14
// RUN: %clang_cc1 -std=c++14 -pedantic-errors %s -verify=expected,cxx98-14
// RUN: %clang_cc1 -std=c++17 -pedantic-errors %s -verify=expected,since-cxx17
// RUN: %clang_cc1 -std=c++20 -pedantic-errors %s -verify=expected,since-cxx17
// RUN: %clang_cc1 -std=c++23 -pedantic-errors %s -verify=expected,since-cxx17
// RUN: %clang_cc1 -std=c++2c -pedantic-errors %s -verify=expected,since-cxx17

#if __cplusplus <= 201402L
// expected-no-diagnostics
#endif

namespace cwg2406 { // cwg2406: 5
#if __cplusplus >= 201703L
void fallthrough(int n) {
Expand Down Expand Up @@ -186,3 +182,36 @@ namespace cwg2445 { // cwg2445: 19
}
#endif
}

namespace cwg2486 { // cwg2486: 4 c++17
struct C {
void fn() throw();
};

static void call(C& c, void (C::*f)()) {
(c.*f)();
}

static void callNE(C& c, void (C::*f)() throw()) {
// cxx98-14-warning@-1 {{mangled name of 'callNE' will change in C++17 due to non-throwing exception specification in function signature}}
(c.*f)();
}

void ref() {
C c;
call(c, &C::fn); // <= implicit cast removes noexcept
callNE(c, &C::fn);
}

void (*p)();
void (*pp)() throw() = p;
// since-cxx17-error@-1 {{cannot initialize a variable of type 'void (*)() throw()' with an lvalue of type 'void (*)()': different exception specifications}}

struct S {
typedef void (*p)();
operator p(); // #cwg2486-conv
};
void (*q)() throw() = S();
// since-cxx17-error@-1 {{no viable conversion from 'S' to 'void (*)() throw()'}}
// since-cxx17-note@#cwg2486-conv {{candidate function}}
} // namespace cwg2486
2 changes: 1 addition & 1 deletion clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -14751,7 +14751,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2486.html">2486</a></td>
<td>CD6</td>
<td>Call to <TT>noexcept</TT> function via <TT>noexcept(false)</TT> pointer/lvalue</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Clang 4 (C++17 onwards)</td>
</tr>
<tr class="open" id="2487">
<td><a href="https://cplusplus.github.io/CWG/issues/2487.html">2487</a></td>
Expand Down

0 comments on commit eaa95a1

Please sign in to comment.