public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107782] New: constexpr volatile variable is permitted to appear in a constant expression
@ 2022-11-21  7:26 fchelnokov at gmail dot com
  2022-11-21  8:00 ` [Bug c++/107782] a local constexpr volatile variable cannot be used to initialize a local constexpr volatile variable pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: fchelnokov at gmail dot com @ 2022-11-21  7:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107782
           Summary: constexpr volatile variable is permitted to appear in
                    a constant expression
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

int main() {
    constexpr volatile int i = 0;
    constexpr volatile int j = i;
    return j;
}

is properly rejected by Clang since according to
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4093.html#1688
constexpr volatile variable cannot appear in a constant expression.

Unfortunately GCC (and MSVC) accept invalid program. Online demo:
https://gcc.godbolt.org/z/43ee65Peq

Related discussion: https://stackoverflow.com/q/74511594/7325599

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

* [Bug c++/107782] a local constexpr volatile variable cannot be used to initialize a local constexpr volatile variable
  2022-11-21  7:26 [Bug c++/107782] New: constexpr volatile variable is permitted to appear in a constant expression fchelnokov at gmail dot com
@ 2022-11-21  8:00 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-21  8:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|https://gcc.gnu.org/bugzill |
                   |a/show_bug.cgi?id=87497,    |
                   |https://gcc.gnu.org/bugzill |
                   |a/show_bug.cgi?id=89553     |
             Status|UNCONFIRMED                 |NEW
            Summary|constexpr volatile variable |a local constexpr volatile
                   |is permitted to appear in a |variable cannot be used to
                   |constant expression         |initialize a local
                   |                            |constexpr volatile variable
   Last reconfirmed|                            |2022-11-21
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. 
Note GCC only does NOT rejects the local variable case.

That is take:
int main() {
  constexpr volatile int t = 1;
  static constexpr volatile int t1 = t;
  constexpr volatile int t2 = t;
  constexpr int t3 = t;
};

GCC will reject t1 and t3 correctly but not t2.
So GCC is mostly correct except for that one case while MSVC accepts all of the
above.

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

end of thread, other threads:[~2022-11-21  8:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21  7:26 [Bug c++/107782] New: constexpr volatile variable is permitted to appear in a constant expression fchelnokov at gmail dot com
2022-11-21  8:00 ` [Bug c++/107782] a local constexpr volatile variable cannot be used to initialize a local constexpr volatile variable 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).