public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107580] New: std::vector<std::string> cannot be brace initialized with -D_GLIBCXX_USE_CXX11_ABI=0
@ 2022-11-08 19:57 vyas.ramasubramani at gmail dot com
  2022-11-08 22:21 ` [Bug libstdc++/107580] std::vector<std::string> parameter cannot be inferred " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vyas.ramasubramani at gmail dot com @ 2022-11-08 19:57 UTC (permalink / raw)
  To: gcc-bugs

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.

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

* [Bug libstdc++/107580] std::vector<std::string> parameter cannot be inferred with -D_GLIBCXX_USE_CXX11_ABI=0
  2022-11-08 19:57 [Bug libstdc++/107580] New: std::vector<std::string> cannot be brace initialized with -D_GLIBCXX_USE_CXX11_ABI=0 vyas.ramasubramani at gmail dot com
@ 2022-11-08 22:21 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-08 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is expected this is why there was a need for the new
implementation of std::string and why there was a new ABI. the old std::string
is not C++11 compatiable at all. I suspect this is a won't fix.

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

* [Bug libstdc++/107580] std::vector<std::string> parameter cannot be inferred with -D_GLIBCXX_USE_CXX11_ABI=0
  2022-11-08 19:57 [Bug libstdc++/107580] New: std::vector<std::string> cannot be brace initialized with -D_GLIBCXX_USE_CXX11_ABI=0 vyas.ramasubramani at gmail dot com
  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
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-09  4:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
   Last reconfirmed|                            |2022-11-09
     Ever confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is actually trivial to fix:

--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -680,7 +680,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  @param  __end  End of range.
        *  @param  __a  Allocator to use (default is default allocator).
        */
-      template<class _InputIterator>
+#if __cplusplus >= 201103L
+      template<typename _InputIterator,
+              typename = std::_RequireInputIter<_InputIterator>>
+#else
+      template<typename _InputIterator>
+#endif
        basic_string(_InputIterator __beg, _InputIterator __end,
                     const _Alloc& __a = _Alloc())
        : _M_dataplus(_S_construct(__beg, __end, __a), __a)

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

* [Bug libstdc++/107580] std::vector<std::string> parameter cannot be inferred with -D_GLIBCXX_USE_CXX11_ABI=0
  2022-11-08 19:57 [Bug libstdc++/107580] New: std::vector<std::string> cannot be brace initialized with -D_GLIBCXX_USE_CXX11_ABI=0 vyas.ramasubramani at gmail dot com
  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
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-09 18:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ABI
           Assignee|redi at gcc dot gnu.org            |unassigned at gcc dot gnu.org
             Status|ASSIGNED                    |NEW

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Unfortunately this changes the mangled name of the function, and so breaks the
library ABI. Maybe that's why I didn't do it sooner.

There are ways to solve that, but it's not as trivial as I thought.

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

end of thread, other threads:[~2022-11-09 18:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 19:57 [Bug libstdc++/107580] New: std::vector<std::string> cannot be brace initialized with -D_GLIBCXX_USE_CXX11_ABI=0 vyas.ramasubramani at gmail dot com
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

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).