public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal
@ 2023-01-26  6:25 coyorkdow at outlook dot com
  2023-01-27  0:07 ` [Bug c++/108550] " pinskia at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: coyorkdow at outlook dot com @ 2023-01-26  6:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

            Bug ID: 108550
           Summary: the type 'const auto' of 'constexpr' variable is not
                    literal
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: coyorkdow at outlook dot com
  Target Milestone: ---

Created attachment 54344
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54344&action=edit
generated by `-save-temps`

This bug can be triggered in gcc-11 and gcc-12. (I don't have gcc-13 so I
didn't try.)

Here are the codes (the preprocessed file is attached)
```
#include <type_traits>
#include <memory>

template <class Tp>
constexpr auto is_pointer_v = std::is_pointer<Tp>::value;

template <class Tp, decltype(&Tp::operator*)* = nullptr>
auto Wrap1(int) -> std::integral_constant<bool,
is_pointer_v<decltype(std::declval<Tp>().operator->())>>;

template <class Tp>
auto Wrap1(...) -> std::is_pointer<Tp>;

int main() {
  static_assert(!is_pointer_v<std::unique_ptr<int>>); // this line can compile
  static_assert(decltype(Wrap1<std::unique_ptr<int>>(0))::value); // error
  return 0;
}
```

The err msgs
```
% g++-11 a.cc -save-temps
a.cc: In instantiation of 'constexpr const auto is_pointer_v<int*>':
a.cc:8:49:   required by substitution of 'template<class Tp, decltype (&
Tp::operator*)* <anonymous> > std::integral_constant<bool,
is_pointer_v<decltype (declval<Tp>().operator->())> > Wrap1(int) [with Tp =
std::unique_ptr<int>; decltype (& Tp::operator*)* <anonymous> = <missing>]'
a.cc:15:53:   required from here
a.cc:5:16: error: the type 'const auto' of 'constexpr' variable
'is_pointer_v<int*>' is not literal
    5 | constexpr auto is_pointer_v = std::is_pointer<Tp>::value;
      |                ^~~~~~~~~~~~
a.cc:5:16: error: 'const auto is_pointer_v<int*>' has incomplete type
a.cc: In function 'int main()':
a.cc:15:59: error: static assertion failed
   15 |   static_assert(decltype(Wrap1<std::unique_ptr<int>>(0))::value); //
this line incurs error
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
```


GCC version:
```
% gcc-11 -v
Using built-in specs.
COLLECT_GCC=gcc-11
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.3.0_2/bin/../libexec/gcc/x86_64-apple-darwin21/11/lto-wrapper
Target: x86_64-apple-darwin21
Configured with: ../configure --prefix=/usr/local/opt/gcc
--libdir=/usr/local/opt/gcc/lib/gcc/11 --disable-nls --enable-checking=release
--with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran,d
--program-suffix=-11 --with-gmp=/usr/local/opt/gmp
--with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc
--with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd
--with-pkgversion='Homebrew GCC 11.3.0_2'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--enable-libphobos --build=x86_64-apple-darwin21 --with-system-zlib
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Homebrew GCC 11.3.0_2)
```

If remove the parameter `decltype(&Tp::operator*)* = nullptr` then codes can be
compiled. Other parameter like `class =
std::enable_if_t<!std::is_pointer<Tp>::value>` can also trigger.

The error also happens in gcc-12.

There is another similar but unrelated bug
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87512

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
@ 2023-01-27  0:07 ` pinskia at gcc dot gnu.org
  2023-01-27  0:21 ` pinskia at gcc dot gnu.org
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-27  0:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Slightly reduced:
```
#include <type_traits>

struct unique_ptr
{
    int operator->(){return true;};
};

template <class Tp>
constexpr auto is_pointer_v = std::is_pointer<Tp>::value;

template <class Tp, int* = nullptr>
auto Wrap1(int) -> std::integral_constant<bool,
is_pointer_v<decltype(Tp{}.operator->())>>;

template <class Tp>
auto Wrap1(...) -> std::is_pointer<Tp>;

int main() {
  static_assert(!decltype(Wrap1<unique_ptr>(0))::value); // error
  return 0;
}
```

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
  2023-01-27  0:07 ` [Bug c++/108550] " pinskia at gcc dot gnu.org
@ 2023-01-27  0:21 ` pinskia at gcc dot gnu.org
  2023-01-27  0:24 ` [Bug c++/108550] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-27  0:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-01-27

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced all the way (C++14 code):
```
template<class T>
struct is_pointer
{
    static constexpr bool value = false;
};

template<class T, T T1>
struct integral_constant
{
  static constexpr T value = T1;
};

template <class Tp>
constexpr auto is_pointer_v = is_pointer<Tp>::value;

template <class Tp, int = 0>
integral_constant<bool, is_pointer_v<int>> Wrap1();

int main() {
  static_assert(!decltype(Wrap1<int>())::value, ""); // error
  return 0;
}
```

Note the unused default template argument for Wrap1 is needed to produce the
issue. Even the return type of Wrap1 does not need to be dependent either ...

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12/13 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
  2023-01-27  0:07 ` [Bug c++/108550] " pinskia at gcc dot gnu.org
  2023-01-27  0:21 ` pinskia at gcc dot gnu.org
@ 2023-01-27  0:24 ` pinskia at gcc dot gnu.org
  2023-02-20 18:19 ` mpolacek at gcc dot gnu.org
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-27  0:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |5.2.0
   Target Milestone|---                         |10.5
            Summary|the type 'const auto' of    |[10/11/12/13 Regression]
                   |'constexpr' variable is not |the type 'const auto' of
                   |literal                     |'constexpr' variable is not
                   |                            |literal
      Known to fail|                            |5.3.0

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also is_pointer_v needs to be an auto type. If you change it to bool things
start working.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12/13 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (2 preceding siblings ...)
  2023-01-27  0:24 ` [Bug c++/108550] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
@ 2023-02-20 18:19 ` mpolacek at gcc dot gnu.org
  2023-02-20 18:25 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-20 18:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Why is this a regression?  I'm not finding a released version that compiled
this.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12/13 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (3 preceding siblings ...)
  2023-02-20 18:19 ` mpolacek at gcc dot gnu.org
@ 2023-02-20 18:25 ` pinskia at gcc dot gnu.org
  2023-02-20 18:31 ` mpolacek at gcc dot gnu.org
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-20 18:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #4)
> Why is this a regression?  I'm not finding a released version that compiled
> this.

The testcase in comment #2 works both with GCC 5.1.0 and 5.2.0 at least as on
godbolt . GCC 5.3.0 fails though.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12/13 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (4 preceding siblings ...)
  2023-02-20 18:25 ` pinskia at gcc dot gnu.org
@ 2023-02-20 18:31 ` mpolacek at gcc dot gnu.org
  2023-02-20 21:17 ` mpolacek at gcc dot gnu.org
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-20 18:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Ah!

Started with

commit dc062b4986328bfeec3ebd744a9c116e28828bf0
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Aug 5 13:56:14 2015 -0400

    re PR c++/66260 ([C++14] Failure to compile variable template with
recursively defined partial specialization)

            PR c++/66260
            PR c++/66596
            PR c++/66649
            PR c++/66923
            * pt.c (lookup_template_variable): Use NULL_TREE for type.
            (instantiate_template_1): Also set DECL_TI_ARGS based on
            the immediate parent.
            (tsubst_copy_and_build) [TEMPLATE_ID_EXPR]: Handle variable
templates.
            (finish_template_variable): Add complain parm.
            * cp-tree.h: Adjust.

    From-SVN: r226642

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12/13 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (5 preceding siblings ...)
  2023-02-20 18:31 ` mpolacek at gcc dot gnu.org
@ 2023-02-20 21:17 ` mpolacek at gcc dot gnu.org
  2023-02-21 12:52 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-20 21:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
We get the bogus error because we failed to deduce the auto in
constexpr auto is_pointer_v = is_pointer<Tp>::value;
to bool.

We call do_auto_deduction and type_unification_real correctly deduces targs to
<bool>, but the tsubst at the end of do_auto_deduction doesn't use the bool to
replace arg, which is

(gdb) pt
 <template_type_parm 0x7fffea3c6150 auto readonly type_0 type_6 VOID
    align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7fffea3c6150
   index 0 level 2 orig_level 2>

but levels = TMPL_ARGS_DEPTH (args); is 1, so the
  if (level <= levels
block isn't performed, so we don't fetch the bool from args.

It looks like another case where 'auto' has a level that we don't handle
correctly.  I think the level for placeholders is created + 1 than the normal
one (at least it used to be), so orig_level 2 is probably correct, but level
should probably have been reduced to 1.

I need to poke more...

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12/13 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (6 preceding siblings ...)
  2023-02-20 21:17 ` mpolacek at gcc dot gnu.org
@ 2023-02-21 12:52 ` rguenth at gcc dot gnu.org
  2023-02-21 16:28 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-21 12:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12/13 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (7 preceding siblings ...)
  2023-02-21 12:52 ` rguenth at gcc dot gnu.org
@ 2023-02-21 16:28 ` mpolacek at gcc dot gnu.org
  2023-02-28 15:16 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-21 16:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Potential fix:

--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -10355,6 +10355,7 @@ lookup_and_finish_template_variable (tree templ, tree
targs,
   if (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (templ)) == 1
       && !any_dependent_template_arguments_p (targs))
     {
+      complain &= ~tf_partial;
       var = finish_template_variable (var, complain);
       mark_used (var);
     }

but I need to think some more about it.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12/13 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (8 preceding siblings ...)
  2023-02-21 16:28 ` mpolacek at gcc dot gnu.org
@ 2023-02-28 15:16 ` cvs-commit at gcc dot gnu.org
  2023-02-28 15:16 ` [Bug c++/108550] [10/11/12 " mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-28 15:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:d918c3a221434521f90cc9b63d5d87f5129e9231

commit r13-6377-gd918c3a221434521f90cc9b63d5d87f5129e9231
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Feb 21 19:13:59 2023 -0500

    c++: variable template and targ deduction [PR108550]

    In this test, we get a bogus error because we failed to deduce the auto in
    constexpr auto is_pointer_v = is_pointer<Tp>::value;
    to bool.  Then ensure_literal_type_for_constexpr_object thinks the object
    isn't literal and an error is reported.

    This is another case of the interaction between tf_partial and 'auto',
    where the auto was not reduced so the deduction failed.  In more detail:
    we have

      Wrap1<int>()

    in the code and we need to perform OR -> fn_type_unification.  The targ
    list is incomplete, so we do
          tsubst_flags_t ecomplain = complain | tf_partial | tf_fndecl_type;
          fntype = tsubst (TREE_TYPE (fn), explicit_targs, ecomplain,
NULL_TREE);
    where TREE_TYPE (fn) is struct integral_constant <T402> (void).  Then
    we substitute the return type, which results in tsubsting
is_pointer_v<int>.
    is_pointer_v is a variable template with a placeholder type:

      template <class Tp>
      constexpr auto is_pointer_v = is_pointer<Tp>::value;

    so we find ourselves in lookup_and_finish_template_variable.  tf_partial is
    still set, so finish_template_variable -> instantiate_template -> tsubst
    won't reduce the level of auto.  But then we do mark_used which eventually
    calls do_auto_deduction which clears tf_partial, because we want to replace
    the auto now.  But we hadn't reduced auto's level so this fails.  And
    since we're not in an immediate context, we emit a hard error.

    I suppose that when we reach lookup_and_finish_template_variable it's
    probably time to clear tf_partial.  (I added an assert and our testsuite
    doesn't have a test whereby we get to lookup_and_finish_template_variable
    while tf_partial is still active.)

            PR c++/108550

    gcc/cp/ChangeLog:

            * pt.cc (lookup_and_finish_template_variable): Clear tf_partial.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/var-templ70.C: New test.
            * g++.dg/cpp1y/var-templ71.C: New test.
            * g++.dg/cpp1y/var-templ72.C: New test.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (9 preceding siblings ...)
  2023-02-28 15:16 ` cvs-commit at gcc dot gnu.org
@ 2023-02-28 15:16 ` mpolacek at gcc dot gnu.org
  2023-03-04 18:14 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-28 15:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11/12/13 Regression]    |[10/11/12 Regression] the
                   |the type 'const auto' of    |type 'const auto' of
                   |'constexpr' variable is not |'constexpr' variable is not
                   |literal                     |literal

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (10 preceding siblings ...)
  2023-02-28 15:16 ` [Bug c++/108550] [10/11/12 " mpolacek at gcc dot gnu.org
@ 2023-03-04 18:14 ` cvs-commit at gcc dot gnu.org
  2023-03-04 18:18 ` mpolacek at gcc dot gnu.org
  2023-03-04 18:25 ` mpolacek at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-04 18:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:d6419c18056ae27741e961cd2dab9d120bfe746a

commit r12-9219-gd6419c18056ae27741e961cd2dab9d120bfe746a
Author: Marek Polacek <polacek@redhat.com>
Date:   Sat Mar 4 13:14:01 2023 -0500

    c++: variable template and targ deduction [PR108550]

    In this test, we get a bogus error because we failed to deduce the auto in
    constexpr auto is_pointer_v = is_pointer<Tp>::value;
    to bool.  Then ensure_literal_type_for_constexpr_object thinks the object
    isn't literal and an error is reported.

    This is another case of the interaction between tf_partial and 'auto',
    where the auto was not reduced so the deduction failed.  In more detail:
    we have

      Wrap1<int>()

    in the code and we need to perform OR -> fn_type_unification.  The targ
    list is incomplete, so we do
          tsubst_flags_t ecomplain = complain | tf_partial | tf_fndecl_type;
          fntype = tsubst (TREE_TYPE (fn), explicit_targs, ecomplain,
NULL_TREE);
    where TREE_TYPE (fn) is struct integral_constant <T402> (void).  Then
    we substitute the return type, which results in tsubsting
is_pointer_v<int>.
    is_pointer_v is a variable template with a placeholder type:

      template <class Tp>
      constexpr auto is_pointer_v = is_pointer<Tp>::value;

    so we find ourselves in lookup_and_finish_template_variable.  tf_partial is
    still set, so finish_template_variable -> instantiate_template -> tsubst
    won't reduce the level of auto.  But then we do mark_used which eventually
    calls do_auto_deduction which clears tf_partial, because we want to replace
    the auto now.  But we hadn't reduced auto's level so this fails.  And
    since we're not in an immediate context, we emit a hard error.

    I suppose that when we reach lookup_and_finish_template_variable it's
    probably time to clear tf_partial.  (I added an assert and our testsuite
    doesn't have a test whereby we get to lookup_and_finish_template_variable
    while tf_partial is still active.)

            PR c++/108550

    gcc/cp/ChangeLog:

            * pt.cc (lookup_and_finish_template_variable): Clear tf_partial.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/var-templ70.C: New test.
            * g++.dg/cpp1y/var-templ71.C: New test.
            * g++.dg/cpp1y/var-templ72.C: New test.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (11 preceding siblings ...)
  2023-03-04 18:14 ` cvs-commit at gcc dot gnu.org
@ 2023-03-04 18:18 ` mpolacek at gcc dot gnu.org
  2023-03-04 18:25 ` mpolacek at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-04 18:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/108550] [10/11/12 Regression] the type 'const auto' of 'constexpr' variable is not literal
  2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
                   ` (12 preceding siblings ...)
  2023-03-04 18:18 ` mpolacek at gcc dot gnu.org
@ 2023-03-04 18:25 ` mpolacek at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-04 18:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108550

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #12 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-03-04 18:25 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26  6:25 [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal coyorkdow at outlook dot com
2023-01-27  0:07 ` [Bug c++/108550] " pinskia at gcc dot gnu.org
2023-01-27  0:21 ` pinskia at gcc dot gnu.org
2023-01-27  0:24 ` [Bug c++/108550] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
2023-02-20 18:19 ` mpolacek at gcc dot gnu.org
2023-02-20 18:25 ` pinskia at gcc dot gnu.org
2023-02-20 18:31 ` mpolacek at gcc dot gnu.org
2023-02-20 21:17 ` mpolacek at gcc dot gnu.org
2023-02-21 12:52 ` rguenth at gcc dot gnu.org
2023-02-21 16:28 ` mpolacek at gcc dot gnu.org
2023-02-28 15:16 ` cvs-commit at gcc dot gnu.org
2023-02-28 15:16 ` [Bug c++/108550] [10/11/12 " mpolacek at gcc dot gnu.org
2023-03-04 18:14 ` cvs-commit at gcc dot gnu.org
2023-03-04 18:18 ` mpolacek at gcc dot gnu.org
2023-03-04 18:25 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).