diff options
author | Jason Merrill <jason@redhat.com> | 2018-05-24 16:03:18 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2018-05-24 16:03:18 -0400 |
commit | 520fe2e324da4b1aa2c1fbac29741bd45afa98c1 (patch) | |
tree | d5ee3da1e28a5623631a66ec4704faa85a30cfb6 /gcc | |
parent | 71b55d45e4304f5e2e98ac30473c581f58fc486b (diff) | |
download | gcc-520fe2e324da4b1aa2c1fbac29741bd45afa98c1.zip gcc-520fe2e324da4b1aa2c1fbac29741bd45afa98c1.tar.gz gcc-520fe2e324da4b1aa2c1fbac29741bd45afa98c1.tar.bz2 |
PR c++/85842 - -Wreturn-type, constexpr if and generic lambda.
* pt.c (tsubst_lambda_expr): Copy current_function_returns_* to
generic lambda.
From-SVN: r260685
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/pt.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C | 13 |
3 files changed, 30 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fdf73d1..371c8b7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-05-24 Jason Merrill <jason@redhat.com> + + PR c++/85842 - -Wreturn-type, constexpr if and generic lambda. + * pt.c (tsubst_lambda_expr): Copy current_function_returns_* to + generic lambda. + 2018-05-24 Ville Voutilainen <ville.voutilainen@gmail.com> Pedwarn on a non-standard position of a C++ attribute. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index cfce9a9..d0fc9ee 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17636,6 +17636,17 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) register_parameter_specializations (oldfn, fn); + if (oldtmpl) + { + /* We might not partially instantiate some parts of the function, so + copy these flags from the original template. */ + language_function *ol = DECL_STRUCT_FUNCTION (oldfn)->language; + current_function_returns_value = ol->returns_value; + current_function_returns_null = ol->returns_null; + current_function_returns_abnormally = ol->returns_abnormally; + current_function_infinite_loop = ol->infinite_loop; + } + tsubst_expr (DECL_SAVED_TREE (oldfn), args, complain, r, /*constexpr*/false); diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C new file mode 100644 index 0000000..8e31db3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if23.C @@ -0,0 +1,13 @@ +// PR c++/85842 +// { dg-additional-options -std=c++17 } + +template<class T> +auto f = [](auto&& arg) -> T* { + if constexpr (sizeof(arg) == 1) { + return nullptr; + } else { + return static_cast<T*>(&arg); + } +}; + +auto p = f<int>(0); |