From: Marek Polacek Date: Tue, 8 May 2018 19:30:57 +0000 (+0000) Subject: re PR c++/85695 (if constexpr misevaluates typedefed type value) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0e45c664e3f08eac144e82918a38174873ec176d;p=gcc.git re PR c++/85695 (if constexpr misevaluates typedefed type value) PR c++/85695 * semantics.c (finish_if_stmt_cond): See through typedefs. * g++.dg/cpp1z/constexpr-if22.C: New test. From-SVN: r260049 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 65991150ef0..d80c15d2168 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-05-08 Marek Polacek + + PR c++/85695 + * semantics.c (finish_if_stmt_cond): See through typedefs. + 2018-05-07 Jason Merrill PR c++/85646 - lambda visibility. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 2b2b51b2a7e..195286ca751 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -736,7 +736,7 @@ finish_if_stmt_cond (tree cond, tree if_stmt) && !instantiation_dependent_expression_p (cond) /* Wait until instantiation time, since only then COND has been converted to bool. */ - && TREE_TYPE (cond) == boolean_type_node) + && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node) { cond = instantiate_non_dependent_expr (cond); cond = cxx_constant_value (cond, NULL_TREE); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dc19677d02c..3bfeb894b9b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-05-08 Marek Polacek + + PR c++/85695 + * g++.dg/cpp1z/constexpr-if22.C: New test. + 2018-05-08 Uros Bizjak PR target/85693 diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if22.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if22.C new file mode 100644 index 00000000000..76f0c73476b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if22.C @@ -0,0 +1,21 @@ +// PR c++/85695 +// { dg-options -std=c++17 } + +template +struct integral_constant { + using value_type = T; + static constexpr const value_type value = v; + constexpr operator value_type (void) const { return value; } +}; +template struct is_trivial + : public integral_constant {}; + +template +T clone_object (const T& p) +{ + if constexpr (is_trivial::value) + return p; + else + return p.clone(); +} +int main (void) { return clone_object(0); }