public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115030] New: Constrained auto variable declaration with partial specialization
@ 2024-05-10 13:34 sska1377 at gmail dot com
  2024-05-10 13:36 ` [Bug c++/115030] " sska1377 at gmail dot com
  2024-05-10 13:38 ` sska1377 at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: sska1377 at gmail dot com @ 2024-05-10 13:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115030
           Summary: Constrained auto variable declaration with partial
                    specialization
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sska1377 at gmail dot com
  Target Milestone: ---

Created attachment 58173
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58173&action=edit
the code

This is a simple valid code that uses a constrained auto placeholder that is
dependent on template parameters, in a partial specialization variable
template.

// report_1.cc
template<typename T, typename U>
concept TheConcept = __is_same(T, U);

template <typename T>
struct A {
};

template <typename T>
char v = 'a';

template<typename T>
TheConcept<T> auto v<A<T>> = 'c';

int main() {
  v<A<char>>;
  return 0;
}

which fails with the following error:

$ g++ report_1.cc  --std=c++20
report_1.cc: In instantiation of 'auto [requires ::TheConcept<<placeholder>,
T>] v<A<char> >':
report_1.cc:15:3:   required from here
   15 |   v<A<char>>;
      |   ^~~~~~~~~~
report_1.cc:12:30: error: deduced initializer does not satisfy placeholder
constraints
   12 | TheConcept<T> auto v<A<T>> = 'c';
      |                              ^~~
report_1.cc:12:30: note: constraints not satisfied
report_1.cc:2:9:   required for the satisfaction of 'TheConcept<auto [requires
::TheConcept<<placeholder>, T>], T>' [with auto [requires
::TheConcept<<placeholder>, T>] = char; T = A<char>]
report_1.cc:2:22: note:   'char' is not the same as 'A<char>'
    2 | concept TheConcept = __is_same(T, U);
      |                      ^~~~~~~~~~~~~~~


This has been tested using:
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.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,m2,objc,obj-c++,rust
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--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 14.1.1 20240507 (GCC)

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

* [Bug c++/115030] Constrained auto variable declaration with partial specialization
  2024-05-10 13:34 [Bug c++/115030] New: Constrained auto variable declaration with partial specialization sska1377 at gmail dot com
@ 2024-05-10 13:36 ` sska1377 at gmail dot com
  2024-05-10 13:38 ` sska1377 at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: sska1377 at gmail dot com @ 2024-05-10 13:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Seyed Sajad Kahani <sska1377 at gmail dot com> ---
Created attachment 58176
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58176&action=edit
report_2.cc, additional invalid code


Moreover, by replacing 'c' with A<char>{} that makes it an invalid code (see
attached report_2.cc) will compile successfully.

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

* [Bug c++/115030] Constrained auto variable declaration with partial specialization
  2024-05-10 13:34 [Bug c++/115030] New: Constrained auto variable declaration with partial specialization sska1377 at gmail dot com
  2024-05-10 13:36 ` [Bug c++/115030] " sska1377 at gmail dot com
@ 2024-05-10 13:38 ` sska1377 at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: sska1377 at gmail dot com @ 2024-05-10 13:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Seyed Sajad Kahani <sska1377 at gmail dot com> ---
Created attachment 58177
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58177&action=edit
a similar code that works, as a clue (clue_1.cc)


Additionally, the problem will disappear by enclosing variable in a class (see
attached clue.cc)

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

end of thread, other threads:[~2024-05-10 13:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-10 13:34 [Bug c++/115030] New: Constrained auto variable declaration with partial specialization sska1377 at gmail dot com
2024-05-10 13:36 ` [Bug c++/115030] " sska1377 at gmail dot com
2024-05-10 13:38 ` sska1377 at gmail dot com

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).