public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vyas.ramasubramani at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/107580] New: std::vector<std::string> cannot be brace initialized with -D_GLIBCXX_USE_CXX11_ABI=0
Date: Tue, 08 Nov 2022 19:57:11 +0000	[thread overview]
Message-ID: <bug-107580-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 107580
           Summary: std::vector<std::string> cannot be brace initialized
                    with -D_GLIBCXX_USE_CXX11_ABI=0
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vyas.ramasubramani at gmail dot com
  Target Milestone: ---

The type of the argument to the constructor of A cannot be correctly inferred
when using the old ABI:

#include <string>
#include <vector>
struct A {
    A(std::string const& file_path) {}
    A(std::vector<std::string> const& file_path) {}
};

int main() {
    std::string x = "hello";
    std::string y = "goodbye";
    // Both of the below will fail.
    A a{{x, y}};
    A a = A({x, y});
}

Here's the output from running the compilation:

(test_gcc) vyasr-dt% g++ test.cpp -D_GLIBCXX_USE_CXX11_ABI=0
test.cpp: In function ‘int main()’:
test.cpp:11:16: error: call of overloaded ‘A(<brace-enclosed initializer
list>)’ is ambiguous
   11 |     A a1{{x, y}};
      |                ^
test.cpp:5:5: note: candidate: ‘A::A(const std::vector<std::basic_string<char>
>&)’
    5 |     A(std::vector<std::string> const& file_path) {}
      |     ^
test.cpp:4:5: note: candidate: ‘A::A(const string&)’
    4 |     A(std::string const& file_path) {}
      |     ^
test.cpp:12:20: error: call of overloaded ‘A(<brace-enclosed initializer
list>)’ is ambiguous
   12 |     A a2 = A({x, y});
      |                    ^
test.cpp:5:5: note: candidate: ‘A::A(const std::vector<std::basic_string<char>
>&)’
    5 |     A(std::vector<std::string> const& file_path) {}
      |     ^
test.cpp:4:5: note: candidate: ‘A::A(const string&)’
    4 |     A(std::string const& file_path) {}
      |     ^

And here is my current version information:

(test_gcc) vyasr-dt% g++ -v       
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-9
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1) 


Here is an example using the Compiler Explorer showing that this issue is
specific to libstdc++ and the old ABI flag: https://godbolt.org/z/jqoc6j3be.
For instance, with clang the error appears unless `-stdlib=libc++` is
specified, at which point the code compiles successfully.

             reply	other threads:[~2022-11-08 19:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08 19:57 vyas.ramasubramani at gmail dot com [this message]
2022-11-08 22:21 ` [Bug libstdc++/107580] std::vector<std::string> parameter cannot be inferred " pinskia at gcc dot gnu.org
2022-11-09  4:30 ` redi at gcc dot gnu.org
2022-11-09 18:54 ` redi 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-107580-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).