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
This commit is contained in:
Marek Polacek 2018-05-08 19:30:57 +00:00 committed by Marek Polacek
parent 3b275e65cb
commit 0e45c664e3
4 changed files with 32 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2018-05-08 Marek Polacek <polacek@redhat.com>
PR c++/85695
* semantics.c (finish_if_stmt_cond): See through typedefs.
2018-05-07 Jason Merrill <jason@redhat.com>
PR c++/85646 - lambda visibility.

View File

@ -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);

View File

@ -1,3 +1,8 @@
2018-05-08 Marek Polacek <polacek@redhat.com>
PR c++/85695
* g++.dg/cpp1z/constexpr-if22.C: New test.
2018-05-08 Uros Bizjak <ubizjak@gmail.com>
PR target/85693

View File

@ -0,0 +1,21 @@
// PR c++/85695
// { dg-options -std=c++17 }
template <typename T, T v>
struct integral_constant {
using value_type = T;
static constexpr const value_type value = v;
constexpr operator value_type (void) const { return value; }
};
template <typename T> struct is_trivial
: public integral_constant<bool, __is_trivial(T)> {};
template <typename T>
T clone_object (const T& p)
{
if constexpr (is_trivial<T>::value)
return p;
else
return p.clone();
}
int main (void) { return clone_object(0); }