diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-03-27 10:04:31 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-03-27 10:04:31 +0100 |
commit | 2eea00c518d5a72d0bdbc810ae675e7ad5fee414 (patch) | |
tree | 849b1af02a1b827954270c6978e5478019366807 /gcc/testsuite/g++.dg | |
parent | 72809d6fe8e085440403ce125c51d01d6e7512b0 (diff) | |
download | gcc-2eea00c518d5a72d0bdbc810ae675e7ad5fee414.zip gcc-2eea00c518d5a72d0bdbc810ae675e7ad5fee414.tar.gz gcc-2eea00c518d5a72d0bdbc810ae675e7ad5fee414.tar.bz2 |
c++: Avoid calls in non-evaluated contexts affect whether function can or can't throw [PR94326]
The following testcase FAILs -fcompare-debug, because if we emit a
-Wreturn-local-addr warning, we tsubst decltype in order to print the
warning and as that function could throw, set_flags_from_callee during that
sets cp_function_chain->can_throw and later on we don't set TREE_NOTHROW
on foo. While with -w or -Wno-return-local-addr, tsubst isn't called during
the warning_at, cp_function_chain->can_throw is kept clear and TREE_NOTHROW
is set on foo.
It isn't just a matter of the warning though, in
int foo ();
int bar () { return sizeof (foo ()); }
int baz () { return sizeof (int); }
I don't really see why we should mark only baz as TREE_NOTHROW and not bar
too, when neither can really throw.
2020-03-27 Jakub Jelinek <jakub@redhat.com>
PR c++/94326
* call.c (set_flags_from_callee): Don't update
cp_function_chain->can_throw or current_function_returns_abnormally
if cp_unevaluated_operand.
* g++.dg/other/pr94326.C: New test.
Diffstat (limited to 'gcc/testsuite/g++.dg')
-rw-r--r-- | gcc/testsuite/g++.dg/other/pr94326.C | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/other/pr94326.C b/gcc/testsuite/g++.dg/other/pr94326.C new file mode 100644 index 0000000..4069c03 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/pr94326.C @@ -0,0 +1,19 @@ +// PR c++/94326 +// { dg-do compile { target c++11 } } +// { dg-options "-fcompare-debug" } + +template <typename = int> struct A { + const int &foo() { return 0; } // { dg-warning "returning reference to temporary" } + template <typename _Kt> void bar(_Kt) { foo(); } +}; +struct B { + A<> b; + template <typename _Kt> auto baz(_Kt p1) -> decltype(b.bar(p1)) { + b.bar(p1); + } +}; +struct C {}; +void operator<(C, int) { + B a; + a.baz(C{}); +} |