Commit fe0604d3 by Marek Polacek Committed by Marek Polacek

re PR c++/85032 (Wrong non-constant condition for static assertion)

	PR c++/85032
	* constexpr.c (potential_constant_expression_1): Consider conversions
	from classes to literal types potentially constant.

	* g++.dg/cpp0x/pr51225.C: Adjust error message.
	* g++.dg/cpp1z/constexpr-if21.C: New test.

From-SVN: r259318
parent 3c7b8651
2018-04-11 Marek Polacek <polacek@redhat.com>
PR c++/85032
* constexpr.c (potential_constant_expression_1): Consider conversions
from classes to literal types potentially constant.
2018-04-10 Paolo Carlini <paolo.carlini@oracle.com> 2018-04-10 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/70808 PR c++/70808
......
...@@ -5777,6 +5777,25 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, ...@@ -5777,6 +5777,25 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
TREE_TYPE (t)); TREE_TYPE (t));
return false; return false;
} }
/* This might be a conversion from a class to a (potentially) literal
type. Let's consider it potentially constant since the conversion
might be a constexpr user-defined conversion. */
else if (cxx_dialect >= cxx11
&& (dependent_type_p (TREE_TYPE (t))
|| !COMPLETE_TYPE_P (TREE_TYPE (t))
|| literal_type_p (TREE_TYPE (t)))
&& TREE_OPERAND (t, 0))
{
tree type = TREE_TYPE (TREE_OPERAND (t, 0));
/* If this is a dependent type, it could end up being a class
with conversions. */
if (type == NULL_TREE || WILDCARD_TYPE_P (type))
return true;
/* Or a non-dependent class which has conversions. */
else if (CLASS_TYPE_P (type)
&& (TYPE_HAS_CONVERSION (type) || dependent_scope_p (type)))
return true;
}
return (RECUR (TREE_OPERAND (t, 0), return (RECUR (TREE_OPERAND (t, 0),
TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE)); TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE));
......
2018-04-11 Marek Polacek <polacek@redhat.com>
PR c++/85032
* g++.dg/cpp0x/pr51225.C: Adjust error message.
* g++.dg/cpp1z/constexpr-if21.C: New test.
2018-04-11 Jakub Jelinek <jakub@redhat.com> 2018-04-11 Jakub Jelinek <jakub@redhat.com>
PR target/85281 PR target/85281
......
...@@ -5,7 +5,7 @@ template<int> struct A {}; ...@@ -5,7 +5,7 @@ template<int> struct A {};
template<typename> void foo() template<typename> void foo()
{ {
A<int(x)> a; // { dg-error "not declared|invalid type" } A<int(x)> a; // { dg-error "not declared|could not convert" }
} }
template<typename> struct bar template<typename> struct bar
......
// PR c++/85032
// { dg-options -std=c++17 }
struct A
{
constexpr operator bool () { return true; }
int i;
};
A a;
template <class T>
void f()
{
constexpr bool b = a;
static_assert (a);
}
int main()
{
f<int>();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment