public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result
@ 2022-09-04 17:57 johelegp at gmail dot com
  2022-09-05 18:59 ` [Bug c++/106826] [13 Regression] " johelegp at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: johelegp at gmail dot com @ 2022-09-04 17:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106826
           Summary: [modules] Variable template of type trait via
                    importable header gives wrong result
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/Yjrcv6sG1.

```sh
CXX=/home/johel/root/gcc/bin/g++
echo "./my.std.headers.hpp my.std.headers.gcm
my.std my.std.gcm
my.module my.module.gcm" > mm.txt
echo "#include <type_traits>" > my.std.headers.hpp
echo "export module my.std;
export import \"my.std.headers.hpp\";" > my.std.cpp
echo "export module my.module;
import my.std;
static_assert(std::is_lvalue_reference_v<int&>);
export int _;" > my.module.cpp
$CXX -std=c++23 -fmodules-ts -fmodule-mapper=mm.txt -x c++-header -c
my.std.headers.hpp
$CXX -std=c++23 -fmodules-ts -fmodule-mapper=mm.txt -c my.std.cpp
$CXX -std=c++23 -fmodules-ts -fmodule-mapper=mm.txt -c my.module.cpp
```

Output:
```
my.module.cpp:3:20: error: static assertion failed
    3 | static_assert(std::is_lvalue_reference_v<int&>);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
my.module.cpp:1:8: warning: not writing module ‘my.module’ due to errors
    1 | export module my.module;
      |        ^~~~~~
```

GCC12 passes the assertion.

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

* [Bug c++/106826] [13 Regression] [modules] Variable template of type trait via importable header gives wrong result
  2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
@ 2022-09-05 18:59 ` johelegp at gmail dot com
  2022-09-21 12:29 ` ppalka at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: johelegp at gmail dot com @ 2022-09-05 18:59 UTC (permalink / raw)
  To: gcc-bugs

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

Johel Ernesto Guerrero Peña <johelegp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |12.2.0
      Known to fail|                            |13.0
            Summary|[modules] Variable template |[13 Regression] [modules]
                   |of type trait via           |Variable template of type
                   |importable header gives     |trait via importable header
                   |wrong result                |gives wrong result

--- Comment #1 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
As mentioned, this works with GCC 12: https://godbolt.org/z/bnfzPc5M8.

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

* [Bug c++/106826] [13 Regression] [modules] Variable template of type trait via importable header gives wrong result
  2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
  2022-09-05 18:59 ` [Bug c++/106826] [13 Regression] " johelegp at gmail dot com
@ 2022-09-21 12:29 ` ppalka at gcc dot gnu.org
  2022-09-22  5:04 ` johelegp at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-09-21 12:29 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
                 CC|                            |ppalka at gcc dot gnu.org
     Ever confirmed|0                           |1
   Target Milestone|---                         |13.0
   Last reconfirmed|                            |2022-09-21

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed, likely started with r13-2351-g33005a4be49466 though it's ultimately
a latent modules bug.  Reduced testcase:

$ cat 106826_a.C
export module pr106826;
template<class T> constexpr bool is_lvalue_reference_v = false;
template<class T> constexpr bool is_lvalue_reference_v<T&> = true;
$ cat 106826_b.C
module pr106826;
static_assert(is_lvalue_reference_v<int&>);
$ g++ -fmodules-ts 106826_a.C
$ g++ -fmodules-ts 106826_b.C
106826_b.C:2:15: error: static assertion failed

It looks variable template partial specializations get lost during streaming.

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

* [Bug c++/106826] [13 Regression] [modules] Variable template of type trait via importable header gives wrong result
  2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
  2022-09-05 18:59 ` [Bug c++/106826] [13 Regression] " johelegp at gmail dot com
  2022-09-21 12:29 ` ppalka at gcc dot gnu.org
@ 2022-09-22  5:04 ` johelegp at gmail dot com
  2022-09-22 12:47 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: johelegp at gmail dot com @ 2022-09-22  5:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
So this is a duplicate of Bug 100687.

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

* [Bug c++/106826] [13 Regression] [modules] Variable template of type trait via importable header gives wrong result
  2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
                   ` (2 preceding siblings ...)
  2022-09-22  5:04 ` johelegp at gmail dot com
@ 2022-09-22 12:47 ` cvs-commit at gcc dot gnu.org
  2022-09-22 12:56 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-22 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:32d8123cd6ce87acb557aec230e8359051316f9f

commit r13-2775-g32d8123cd6ce87acb557aec230e8359051316f9f
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Sep 22 08:46:23 2022 -0400

    c++ modules: partial variable template specializations [PR106826]

    With partial variable template specializations, it looks like we
    stream the VAR_DECL (i.e. the DECL_TEMPLATE_RESULT of the corresponding
    TEMPLATE_DECL) since process_partial_specialization adds it to the
    specializations table, but we end up never streaming the corresponding
    TEMPLATE_DECL itself that's reachable only from the primary template's
    DECL_TEMPLATE_SPECIALIZATIONS list, which leads to this list being
    incomplete on stream-in.

    The modules machinery already has special logic for streaming partial
    specializations of class templates; this patch attempts to generalize
    it to handle those of variable templates as well.

            PR c++/106826

    gcc/cp/ChangeLog:

            * module.cc (trees_out::decl_value): Use get_template_info in
            the MK_partial case to handle both VAR_DECL and TYPE_DECL.
            (trees_out::key_mergeable): Likewise.
            (trees_in::key_mergeable): Likewise.
            (has_definition): Consider DECL_INITIAL of a partial variable
            template specialization.
            (depset::hash::make_dependency): Handle partial variable template
            specializations too.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/partial-2_a.C: New test.
            * g++.dg/modules/partial-2_b.C: New test.

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

* [Bug c++/106826] [13 Regression] [modules] Variable template of type trait via importable header gives wrong result
  2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
                   ` (3 preceding siblings ...)
  2022-09-22 12:47 ` cvs-commit at gcc dot gnu.org
@ 2022-09-22 12:56 ` ppalka at gcc dot gnu.org
  2022-09-22 12:57 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-09-22 12:56 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

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

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed.

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

* [Bug c++/106826] [13 Regression] [modules] Variable template of type trait via importable header gives wrong result
  2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
                   ` (4 preceding siblings ...)
  2022-09-22 12:56 ` ppalka at gcc dot gnu.org
@ 2022-09-22 12:57 ` ppalka at gcc dot gnu.org
  2022-09-22 14:08 ` johelegp at gmail dot com
  2022-09-25 17:14 ` johelegp at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-09-22 12:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 100687 has been marked as a duplicate of this bug. ***

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

* [Bug c++/106826] [13 Regression] [modules] Variable template of type trait via importable header gives wrong result
  2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
                   ` (5 preceding siblings ...)
  2022-09-22 12:57 ` ppalka at gcc dot gnu.org
@ 2022-09-22 14:08 ` johelegp at gmail dot com
  2022-09-25 17:14 ` johelegp at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: johelegp at gmail dot com @ 2022-09-22 14:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
Thank you very much! This was a real blocker.

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

* [Bug c++/106826] [13 Regression] [modules] Variable template of type trait via importable header gives wrong result
  2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
                   ` (6 preceding siblings ...)
  2022-09-22 14:08 ` johelegp at gmail dot com
@ 2022-09-25 17:14 ` johelegp at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: johelegp at gmail dot com @ 2022-09-25 17:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
The original reproducer now ICEs. I opened Bug 107033 for this. The tests added
in https://gcc.gnu.org/g:32d8123cd6ce87acb557aec230e8359051316f9f uses a named
module. My reproducer uses an importable header.

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

end of thread, other threads:[~2022-09-25 17:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04 17:57 [Bug c++/106826] New: [modules] Variable template of type trait via importable header gives wrong result johelegp at gmail dot com
2022-09-05 18:59 ` [Bug c++/106826] [13 Regression] " johelegp at gmail dot com
2022-09-21 12:29 ` ppalka at gcc dot gnu.org
2022-09-22  5:04 ` johelegp at gmail dot com
2022-09-22 12:47 ` cvs-commit at gcc dot gnu.org
2022-09-22 12:56 ` ppalka at gcc dot gnu.org
2022-09-22 12:57 ` ppalka at gcc dot gnu.org
2022-09-22 14:08 ` johelegp at gmail dot com
2022-09-25 17:14 ` johelegp 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).