On Fri, Oct 30, 2020 at 02:36:00AM +0000, Marek Polacek via Gcc-patches wrote: > We may not call value_dependent_expression_p on expressions that are > not potential constant expressions, otherwise value_d could crash, > as I saw recently (in C++98). So beef up the checking in i_d_e_p. > > This revealed a curious issue: when we have __PRETTY_FUNCTION__ in > a template function, we set its DECL_VALUE_EXPR to error_mark_node > (cp_make_fname_decl), so potential_c_e returns false when it gets it, > but value_dependent_expression_p handles it specially and says true. > This broke lambda-generic-pretty1.C. So take care of that. > > And then also tweak uses_template_parms. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
Hi, This breaks the GCC build for msp430-elf. The large memory model (-mlarge) uses __int20 pointers. In file included from /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/sstream:38, from ../../../../../../libstdc++-v3/src/c++20/sstream-inst.cc:30: /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/istream: In function 'std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT (&)[_Num])': /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/istream:840:26: error: non-constant condition for static assertion 840 | static_assert(_Num <= __gnu_cxx::__numeric_traits<streamsize>::__max); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/istream:840:26: error: the value of '__gnu_cxx::__numeric_traits_integer<__int20>::__max' is not usable in a constant expression In file included from /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/bits/stl_algobase.h:63, from /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/bits/char_traits.h:39, from /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/ios:40, from /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/istream:38, from /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/sstream:38, from ../../../../../../libstdc++-v3/src/c++20/sstream-inst.cc:30: /home/jozef/msp430/gcc/build-msp430/msp430-elf/large/libstdc++-v3/include/ext/numeric_traits.h:78:27: note: '__gnu_cxx::__numeric_traits_integer<__int20>::__max' was not initialized with a constant expression 78 | static const _Value __max = __glibcxx_max(_Value); | ^~~~~ make[9]: *** [Makefile:550: sstream-inst.lo] Error 1 > > gcc/cp/ChangeLog: > > * constexpr.c (potential_constant_expression_1): Treat > __PRETTY_FUNCTION__ inside a template function as > potentially-constant. > * pt.c (uses_template_parms): Call > instantiation_dependent_expression_p instead of > value_dependent_expression_p. > (instantiation_dependent_expression_p): Check > potential_constant_expression before calling > value_dependent_expression_p. > --- > gcc/cp/constexpr.c | 5 +++++ > gcc/cp/pt.c | 5 +++-- > 2 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c > index b46824f128d..c257dfcb2e6 100644 > --- a/gcc/cp/constexpr.c > +++ b/gcc/cp/constexpr.c > @@ -7716,6 +7716,11 @@ potential_constant_expression_1 (tree t, bool > want_rval, bool strict, bool now, > } > return false; > } > + /* Treat __PRETTY_FUNCTION__ inside a template function as > + potentially-constant. */ > + else if (DECL_PRETTY_FUNCTION_P (t) > + && DECL_VALUE_EXPR (t) == error_mark_node) > + return true; > return RECUR (DECL_VALUE_EXPR (t), rval); > } > if (want_rval > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c > index b569644514c..c419fb470ee 100644 > --- a/gcc/cp/pt.c > +++ b/gcc/cp/pt.c > @@ -10755,7 +10755,7 @@ uses_template_parms (tree t) > else if (t == error_mark_node) > dependent_p = false; > else > - dependent_p = value_dependent_expression_p (t); > + dependent_p = instantiation_dependent_expression_p (t); > > processing_template_decl = saved_processing_template_decl; > > @@ -27293,7 +27293,8 @@ bool > instantiation_dependent_expression_p (tree expression) > { > return (instantiation_dependent_uneval_expression_p (expression) > - || value_dependent_expression_p (expression)); > + || (potential_constant_expression (expression) > + && value_dependent_expression_p (expression))); > } > > /* Like type_dependent_expression_p, but it also works while not processing > > base-commit: 4f0606fe4bbf1346f83dd4d0c9060c6b46672a7d > -- > 2.28.0