diff options
author | Alexandre Oliva <aoliva@redhat.com> | 2018-03-06 06:24:40 +0000 |
---|---|---|
committer | Alexandre Oliva <aoliva@gcc.gnu.org> | 2018-03-06 06:24:40 +0000 |
commit | 1ea71a82f9d42684c542147b231afb63e8a6da8f (patch) | |
tree | 20819b137643b69d6eadb2f84b1076132aff78cf /gcc | |
parent | 4900146ce0cf227aee88a1bd3b152c9394c64771 (diff) | |
download | gcc-1ea71a82f9d42684c542147b231afb63e8a6da8f.zip gcc-1ea71a82f9d42684c542147b231afb63e8a6da8f.tar.gz gcc-1ea71a82f9d42684c542147b231afb63e8a6da8f.tar.bz2 |
[PR c++/84492] stmt expr ending with overload
We ICEd when returning a stmt expr that ends with an overloaded
function, because instantiate_type did not know what to do with
STMT_EXPRs. And it shouldn't have to: the expected type of a stmt
expr cannot be used to resolve its value: an unresolved overload
cannot supply the result of a stmt expr. Catch that and report the
error in the stmt expr before we have a chance to instantiate it.
for gcc/cp/ChangeLog
PR c++/84492
* semantics.c (finish_stmt_expr_expr): Reject unresolved
overloads used as stmt expr values.
for gcc/testsuite/ChangeLog
PR c++/84492
* g++.dg/pr84492.C: New.
From-SVN: r258269
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/pr84492.C | 40 |
4 files changed, 59 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3523b7e..cbacda6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-03-06 Alexandre Oliva <aoliva@redhat.com> + + PR c++/84492 + * semantics.c (finish_stmt_expr_expr): Reject unresolved + overloads used as stmt expr values. + 2018-03-05 Jason Merrill <jason@redhat.com> PR c++/84708 - ICE with lambda in local class NSDMI. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index bf5b41e..8a0096d 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2114,7 +2114,14 @@ finish_stmt_expr_expr (tree expr, tree stmt_expr) { tree type = TREE_TYPE (expr); - if (processing_template_decl) + if (type && type_unknown_p (type)) + { + error ("a statement expression is an insufficient context" + " for overload resolution"); + TREE_TYPE (stmt_expr) = error_mark_node; + return error_mark_node; + } + else if (processing_template_decl) { expr = build_stmt (input_location, EXPR_STMT, expr); expr = add_stmt (expr); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a9f66a3..e3e3262 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-06 Alexandre Oliva <aoliva@redhat.com> + + PR c++/84492 + * g++.dg/pr84492.C: New. + 2018-03-05 Bill Schmidt <wschmidt@linux.vnet.ibm.com> * gcc.target/powerpc/spec-barr-1.c: Change called function name to diff --git a/gcc/testsuite/g++.dg/pr84492.C b/gcc/testsuite/g++.dg/pr84492.C new file mode 100644 index 0000000..1a29220 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr84492.C @@ -0,0 +1,40 @@ +// { dg-do compile } +// { dg-options "-fpermissive" } + +template<int> int foo() +{ + return ({ foo; }); // { dg-error "insufficient context" } +} + +int bar() +{ + return ({ foo; }); // { dg-error "insufficient context" } +} + +void bar(int); + +typedef void (*bart)(int); + +bart barf() +{ + return ({ bar; }); // { dg-error "insufficient context" } +} + +bool bark() +{ + return ({ barf; }); // ok, no overload +} + +template <typename T> +class C +{ + static int f(); + bool g() + { + return ({ f; }); // ok, no overload + } + bool g(int) + { + return ({ g; }); // { dg-error "insufficient context" } + } +}; |