public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112715] New: Incorrect handling of template type aliases instantiated from decltype of lambdas
@ 2023-11-26  7:48 gcc at nospam dot scs.stanford.edu
  2023-11-26  7:49 ` [Bug c++/112715] " gcc at nospam dot scs.stanford.edu
  2024-04-13  8:31 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: gcc at nospam dot scs.stanford.edu @ 2023-11-26  7:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112715
           Summary: Incorrect handling of template type aliases
                    instantiated from decltype of lambdas
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at nospam dot scs.stanford.edu
  Target Milestone: ---

Created attachment 56689
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56689&action=edit
File that should compile but doesn't

I'm using g++ version 13.2.1 on arch linux, configured as follows:

~~~~
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.1 20230801 (GCC) 
~~~~

When defining template type aliases, I get bizarrely incorrect types in some
contexts but not others.  For example, the static assertion fails in this code
but should not:

~~~~
#include <type_traits>

template<unsigned int Nbits>
using uintsz = decltype([](auto i){
  if constexpr (i <= 32)
    return 0;
  else
    return 0L;
 }(std::integral_constant<unsigned int, Nbits>{}));

template<unsigned int Nbytes>
constexpr uintsz<8*Nbytes>
f()
{
  return 0;
}

static_assert(std::is_same_v<decltype(f<7>()), uintsz<56>>);
~~~~

Specifically I get the following error:

~~~~
$ g++ -std=c++20 -ggdb -O -Wall -c -o uintsz.o uintsz.cc
uintsz.cc:18:20: error: static assertion failed
   18 | static_assert(std::is_same_v<decltype(f<7>()), uintsz<56>>);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~

This feels like some sort of state corruption in the compiler, because there
are more complicated examples in which gcc rejects other things inside
functions (like rejecting a using type alias and accepting the corresponding
typedef).  I think this example suffices to show the problem, but I could try
to reduce another test case if necessary.  In all cases, clang++ -std=c++20
accepts the code.

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

* [Bug c++/112715] Incorrect handling of template type aliases instantiated from decltype of lambdas
  2023-11-26  7:48 [Bug c++/112715] New: Incorrect handling of template type aliases instantiated from decltype of lambdas gcc at nospam dot scs.stanford.edu
@ 2023-11-26  7:49 ` gcc at nospam dot scs.stanford.edu
  2024-04-13  8:31 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: gcc at nospam dot scs.stanford.edu @ 2023-11-26  7:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from David Mazières <gcc at nospam dot scs.stanford.edu> ---
I should have mentioned, I hereby place the test case in the public domain.

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

* [Bug c++/112715] Incorrect handling of template type aliases instantiated from decltype of lambdas
  2023-11-26  7:48 [Bug c++/112715] New: Incorrect handling of template type aliases instantiated from decltype of lambdas gcc at nospam dot scs.stanford.edu
  2023-11-26  7:49 ` [Bug c++/112715] " gcc at nospam dot scs.stanford.edu
@ 2024-04-13  8:31 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-13  8:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed on the trunk for GCC 14 by the recent lambda template patches.

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

end of thread, other threads:[~2024-04-13  8:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-26  7:48 [Bug c++/112715] New: Incorrect handling of template type aliases instantiated from decltype of lambdas gcc at nospam dot scs.stanford.edu
2023-11-26  7:49 ` [Bug c++/112715] " gcc at nospam dot scs.stanford.edu
2024-04-13  8:31 ` pinskia 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).