Skip to content

Commit 876fa43

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.
1 parent 9739d7e commit 876fa43

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
@@ -1975,6 +1975,17 @@ maybe_check_overriding_exception_spec (tree overrider, tree basefn)
19751975
|| UNPARSED_NOEXCEPT_SPEC_P (over_throw))
19761976
return true;
19771977

1978+
/* We also have to defer checking when we're in a template and couldn't
1979+
instantiate & evaluate the noexcept to true/false. */
1980+
if (processing_template_decl)
1981+
if ((base_throw
1982+
&& base_throw != noexcept_true_spec
1983+
&& base_throw != noexcept_false_spec)
1984+
|| (over_throw
1985+
&& over_throw != noexcept_true_spec
1986+
&& over_throw != noexcept_false_spec))
1987+
return true;
1988+
19781989
if (!comp_except_specs (base_throw, over_throw, ce_derived))
19791990
{
19801991
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)