public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "koncek.marian at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/101800] New: mingw-64 link error with constexpr static variable definition
Date: Fri, 06 Aug 2021 09:55:05 +0000	[thread overview]
Message-ID: <bug-101800-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 101800
           Summary: mingw-64 link error with constexpr static variable
                    definition
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: koncek.marian at gmail dot com
  Target Milestone: ---

Version:
x86_64-w64-mingw32-g++ (GCC) 10.3.1 20210422 (Fedora MinGW 10.3.1-1.fc34)

Using 3 source files:
////////////////////////////////////
<test.hpp>

#pragma once

struct S
{
        const static int value;
};
////////////////////////////////////
<test.cpp>

#include "test.hpp"

constexpr int S::value = 0;
////////////////////////////////////
<main.cpp>

#include "test.hpp"

int main()
{
        return S::value;
}
////////////////////////////////////

Compile with:
$ x86_64-w64-mingw32-g++ -std=c++2a -c test.cpp && x86_64-w64-mingw32-g++
-std=c++2a test.o main.cpp

Results in:
/usr/lib/gcc/x86_64-w64-mingw32/10.3.1/../../../../x86_64-w64-mingw32/bin/ld:
/tmp/ccANpWMi.o:main.cpp:(.rdata$.refptr._ZN1S5valueE[.refptr._ZN1S5valueE]+0x0):
undefined reference to `S::value'
collect2: error: ld returned 1 exit status

Whereas plain g++ is able to link the files in the executable.

Changing the `constexpr` definition to `const` makes mingw link the files
successfully.

             reply	other threads:[~2021-08-06  9:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06  9:55 koncek.marian at gmail dot com [this message]
2021-08-06 10:35 ` [Bug c++/101800] " jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101800-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).