public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94716] New: Address of constexpr variable not usable in constant expression
@ 2020-04-22 15:36 bluescarni at gmail dot com
  2020-04-23  5:14 ` [Bug c++/94716] " marxin at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bluescarni at gmail dot com @ 2020-04-22 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94716
           Summary: Address of constexpr variable not usable in constant
                    expression
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bluescarni at gmail dot com
  Target Milestone: ---

The following code does not compile in GCC trunk:

-----
template <typename T>
inline constexpr char test_impl = 0;

template <typename T>
inline constexpr auto *id = &test_impl<T>;

int main() {
    static_assert(id<int> != id<float>, "should not be equal");
}
-----

The error message:

-----
<source>: In function 'int main()':

<source>:8:27: error: non-constant condition for static assertion

    8 |     static_assert(id<int> != id<float>, "should not be equal");

      |                   ~~~~~~~~^~~~~~~~~~~~

<source>:8:27: error: '((& test_impl<int>) != (& test_impl<float>))' is not a
constant expression

Compiler returned: 1
-----

See on godbolt:

https://godbolt.org/z/CS4D8B

Clang and MSVC accept the code.

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

* [Bug c++/94716] Address of constexpr variable not usable in constant expression
  2020-04-22 15:36 [Bug c++/94716] New: Address of constexpr variable not usable in constant expression bluescarni at gmail dot com
@ 2020-04-23  5:14 ` marxin at gcc dot gnu.org
  2021-08-28 22:27 ` [Bug c++/94716] comparison of address of template variables should be constexpr pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-04-23  5:14 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org
   Last reconfirmed|                            |2020-04-23
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed, ale GCC versions suffer.

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

* [Bug c++/94716] comparison of address of template variables should be constexpr
  2020-04-22 15:36 [Bug c++/94716] New: Address of constexpr variable not usable in constant expression bluescarni at gmail dot com
  2020-04-23  5:14 ` [Bug c++/94716] " marxin at gcc dot gnu.org
@ 2021-08-28 22:27 ` pinskia at gcc dot gnu.org
  2021-09-10 22:46 ` johelegp at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-28 22:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=69681
            Summary|comparison of address of    |comparison of address of
                   |variables should be         |template variables should
                   |constexpr                   |be constexpr

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
template <int> char test_impl = 0;
static_assert(&test_impl<0> != &test_impl<1>, "should not be equal");

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

* [Bug c++/94716] comparison of address of template variables should be constexpr
  2020-04-22 15:36 [Bug c++/94716] New: Address of constexpr variable not usable in constant expression bluescarni at gmail dot com
  2020-04-23  5:14 ` [Bug c++/94716] " marxin at gcc dot gnu.org
  2021-08-28 22:27 ` [Bug c++/94716] comparison of address of template variables should be constexpr pinskia at gcc dot gnu.org
@ 2021-09-10 22:46 ` johelegp at gmail dot com
  2021-12-28 10:40 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: johelegp at gmail dot com @ 2021-09-10 22:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johelegp at gmail dot com

--- Comment #3 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
*** Bug 102267 has been marked as a duplicate of this bug. ***

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

* [Bug c++/94716] comparison of address of template variables should be constexpr
  2020-04-22 15:36 [Bug c++/94716] New: Address of constexpr variable not usable in constant expression bluescarni at gmail dot com
                   ` (2 preceding siblings ...)
  2021-09-10 22:46 ` johelegp at gmail dot com
@ 2021-12-28 10:40 ` pinskia at gcc dot gnu.org
  2022-01-03 12:48 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-28 10:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 91693.

*** This bug has been marked as a duplicate of bug 91693 ***

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

* [Bug c++/94716] comparison of address of template variables should be constexpr
  2020-04-22 15:36 [Bug c++/94716] New: Address of constexpr variable not usable in constant expression bluescarni at gmail dot com
                   ` (3 preceding siblings ...)
  2021-12-28 10:40 ` pinskia at gcc dot gnu.org
@ 2022-01-03 12:48 ` cvs-commit at gcc dot gnu.org
  2022-01-04 19:15 ` ppalka at gcc dot gnu.org
  2022-01-06 16:17 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-03 12:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:91031bffa42fdea3c985727d042cd1882a64be9c

commit r12-6188-g91031bffa42fdea3c985727d042cd1882a64be9c
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jan 3 13:47:53 2022 +0100

    symtab: Fold &a == &b to 0 if folding_initializer [PR94716]

    On Thu, Dec 09, 2021 at 06:09:12PM -0500, Jason Merrill wrote:
    > For the more general comparison of decls like your a != b example above I
    > think clang is in the right; in manifestly constant-evaluated context
    > (folding_initializer) we should return that they are unequal and prevent
a
    > later alias declaration, like we do for comparison to 0 in
    > maybe_nonzero_address.  It's possible that this gives a wrong answer
based
    > on something in another translation unit, but that's unlikely, and taking
    > that chance seems better than rejecting code that needs a constant
answer.

    I agree.  This is an incremental patch to do that.

    2022-01-03  Jakub Jelinek  <jakub@redhat.com>

            PR c++/94716
    gcc/
            * symtab.c: Include fold-const.h.
            (symtab_node::equal_address_to): If folding_initializer is true,
            handle it like memory_accessed.  Simplify.
    gcc/testsuite/
            * gcc.dg/init-compare-1.c: New test.
            * g++.dg/cpp0x/constexpr-compare1.C: New test.
            * g++.dg/cpp1y/constexpr-94716.C: New test.
            * g++.dg/cpp1z/constexpr-compare1.C: New test.

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

* [Bug c++/94716] comparison of address of template variables should be constexpr
  2020-04-22 15:36 [Bug c++/94716] New: Address of constexpr variable not usable in constant expression bluescarni at gmail dot com
                   ` (4 preceding siblings ...)
  2022-01-03 12:48 ` cvs-commit at gcc dot gnu.org
@ 2022-01-04 19:15 ` ppalka at gcc dot gnu.org
  2022-01-06 16:17 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-04 19:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sjeltsch at gmail dot com

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

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

* [Bug c++/94716] comparison of address of template variables should be constexpr
  2020-04-22 15:36 [Bug c++/94716] New: Address of constexpr variable not usable in constant expression bluescarni at gmail dot com
                   ` (5 preceding siblings ...)
  2022-01-04 19:15 ` ppalka at gcc dot gnu.org
@ 2022-01-06 16:17 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-06 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pdimov at gmail dot com

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

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

end of thread, other threads:[~2022-01-06 16:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-22 15:36 [Bug c++/94716] New: Address of constexpr variable not usable in constant expression bluescarni at gmail dot com
2020-04-23  5:14 ` [Bug c++/94716] " marxin at gcc dot gnu.org
2021-08-28 22:27 ` [Bug c++/94716] comparison of address of template variables should be constexpr pinskia at gcc dot gnu.org
2021-09-10 22:46 ` johelegp at gmail dot com
2021-12-28 10:40 ` pinskia at gcc dot gnu.org
2022-01-03 12:48 ` cvs-commit at gcc dot gnu.org
2022-01-04 19:15 ` ppalka at gcc dot gnu.org
2022-01-06 16:17 ` ppalka 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).