Skip to content

Commit c22c3a7

Browse files
committed
c++: wrong looser excep spec for dep noexcept [PR113158]
Here we find ourselves in maybe_check_overriding_exception_spec in a template context where we can't instantiate a dependent noexcept. That's OK, but we have to defer the checking otherwise we give wrong errors. PR c++/113158 gcc/cp/ChangeLog: * search.cc (maybe_check_overriding_exception_spec): Defer checking when a noexcept couldn't be instantiated & evaluated to false/true. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept83.C: New test. (cherry picked from commit 876fa43)
1 parent 294140d commit c22c3a7

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

gcc/cp/search.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,17 @@ maybe_check_overriding_exception_spec (tree overrider, tree basefn)
19281928
|| UNPARSED_NOEXCEPT_SPEC_P (over_throw))
19291929
return true;
19301930

1931+
/* We also have to defer checking when we're in a template and couldn't
1932+
instantiate & evaluate the noexcept to true/false. */
1933+
if (processing_template_decl)
1934+
if ((base_throw
1935+
&& base_throw != noexcept_true_spec
1936+
&& base_throw != noexcept_false_spec)
1937+
|| (over_throw
1938+
&& over_throw != noexcept_true_spec
1939+
&& over_throw != noexcept_false_spec))
1940+
return true;
1941+
19311942
if (!comp_except_specs (base_throw, over_throw, ce_derived))
19321943
{
19331944
auto_diagnostic_group d;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// PR c++/113158
2+
// { dg-do compile { target c++11 } }
3+
4+
template<typename T>
5+
struct V {
6+
static constexpr bool t = false;
7+
};
8+
struct base {
9+
virtual int f() = 0;
10+
};
11+
12+
template<typename T>
13+
struct derived : base {
14+
int f() noexcept(V<T>::t) override;
15+
};
16+
17+
struct base2 {
18+
virtual int f() noexcept = 0;
19+
};
20+
21+
template<bool B>
22+
struct W {
23+
static constexpr bool t = B;
24+
};
25+
26+
template<bool B>
27+
struct derived2 : base2 {
28+
int f() noexcept(W<B>::t) override; // { dg-error "looser exception specification" }
29+
};
30+
31+
void
32+
g ()
33+
{
34+
derived<int> d1;
35+
derived2<false> d2; // { dg-message "required from here" }
36+
derived2<true> d3;
37+
}

0 commit comments

Comments
 (0)