public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102545] New: inlining constexpr is required yet it should not be.
@ 2021-09-30 10:32 e9leyland at outlook dot com
  2021-09-30 13:33 ` [Bug c++/102545] [modules] " e9leyland at outlook dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: e9leyland at outlook dot com @ 2021-09-30 10:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102545
           Summary: inlining constexpr is required yet it should not be.
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: e9leyland at outlook dot com
  Target Milestone: ---

I module file rev.cpp there is the following,

module;

export import <concepts>;
export import <limits>;

export module rev;

namespace rev {

    export inline constexpr auto FAV_TEST_VAL = u8'9';

}

In the consumer file, main.cpp there is this,

import rev;
import <iostream>;

int
main(int, char**)
{
    auto TEST_VAL = rev::FAV_TEST_VAL;
    std::cout << std::hex << int(TEST_VAL) << std::endl;
}

The makefile has,

$ cat Makefile
.PHONY: default
default: main ;

gcmcache:
        g++ -fmodules-ts -std=c++20 -x c++-system-header concepts
        g++ -fmodules-ts -std=c++20 -x c++-system-header limits
        g++ -fmodules-ts -std=c++20 -x c++-system-header iostream

rev.o: rev.cpp
        g++ -c -std=c++20 -fmodules-ts rev.cpp

main: main.cpp rev.o
        g++ -fmodules-ts -std=c++20 -o main main.cpp rev.o

clean:
        rm rev.o main.exe rm -rf gcm.cache

The constexpr must be given the inline specifier to work, because if it is not
there the following error occurs.

$ make
g++ -c -std=c++20 -fmodules-ts rev.cpp
g++ -fmodules-ts -std=c++20 -o main main.cpp rev.o
main.cpp: In function ‘int main(int, char**)’:
main.cpp:7:26: error: ‘FAV_TEST_VAL’ is not a member of ‘rev’
    7 |     auto TEST_VAL = rev::FAV_TEST_VAL;
      |                          ^~~~~~~~~~~~
make: *** [Makefile:13: main] Error 1

Shouldn't the constexpr be sufficient to inline the function from the standard?
In comparison to VS2022 the inline is not required, nor should it be.

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

* [Bug c++/102545] [modules] inlining constexpr is required yet it should not be.
  2021-09-30 10:32 [Bug c++/102545] New: inlining constexpr is required yet it should not be e9leyland at outlook dot com
@ 2021-09-30 13:33 ` e9leyland at outlook dot com
  2021-09-30 13:41 ` jakub at gcc dot gnu.org
  2024-02-11 14:07 ` nshead at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: e9leyland at outlook dot com @ 2021-09-30 13:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Emily Leyland <e9leyland at outlook dot com> ---
Good question, there seems to be some debate. From
en.cppreference.com/w/cpp/language/constexpr, A constexpr specifier used in a
function or static data member (since C++17) declaration implies inline.

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

* [Bug c++/102545] [modules] inlining constexpr is required yet it should not be.
  2021-09-30 10:32 [Bug c++/102545] New: inlining constexpr is required yet it should not be e9leyland at outlook dot com
  2021-09-30 13:33 ` [Bug c++/102545] [modules] " e9leyland at outlook dot com
@ 2021-09-30 13:41 ` jakub at gcc dot gnu.org
  2024-02-11 14:07 ` nshead at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-30 13:41 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
But the above is not a static data member, so it is not inline by default.

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

* [Bug c++/102545] [modules] inlining constexpr is required yet it should not be.
  2021-09-30 10:32 [Bug c++/102545] New: inlining constexpr is required yet it should not be e9leyland at outlook dot com
  2021-09-30 13:33 ` [Bug c++/102545] [modules] " e9leyland at outlook dot com
  2021-09-30 13:41 ` jakub at gcc dot gnu.org
@ 2024-02-11 14:07 ` nshead at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: nshead at gcc dot gnu.org @ 2024-02-11 14:07 UTC (permalink / raw)
  To: gcc-bugs

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

Nathaniel Shead <nshead at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nshead at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED
           Assignee|unassigned at gcc dot gnu.org      |nshead at gcc dot gnu.org
         Resolution|---                         |DUPLICATE
   Target Milestone|---                         |14.0

--- Comment #3 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Fixed for GCC 14 with r14-5826-g726723c4768002.

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

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

end of thread, other threads:[~2024-02-11 14:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30 10:32 [Bug c++/102545] New: inlining constexpr is required yet it should not be e9leyland at outlook dot com
2021-09-30 13:33 ` [Bug c++/102545] [modules] " e9leyland at outlook dot com
2021-09-30 13:41 ` jakub at gcc dot gnu.org
2024-02-11 14:07 ` nshead 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).