Bug 85647 - gcc 5.4.0 always takes c++11 string
Summary: gcc 5.4.0 always takes c++11 string
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-04 09:42 UTC by Sagar Shah
Modified: 2018-05-04 10:04 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sagar Shah 2018-05-04 09:42:49 UTC
Please refer below sample program - 
$ cat string.cpp
#include <iostream>
#include <string>

void foo(const std::string& arg)
{
    std::cout << "foo [" << arg << "]" << std::endl;
}

int main()
{
    std::string arg("123");
    foo(arg);
}

$ g++ --version
_g++ (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ -std=c++98 string.cpp        
$ nm a.out | grep foo                                                                                                               
0000000000400d30 t _GLOBAL__sub_I__Z3fooRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
0000000000400c18 T _Z3fooRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
$ rm a.out
rm: remove regular file `a.out'? y
$ g++ -std=c++14 string.cpp                                                                                                   
$ nm a.out | grep foo
0000000000400d30 t _GLOBAL__sub_I__Z3fooRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
0000000000400c18 T _Z3fooRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

When I compile above program with -std=c++14 and -std=c++98, I see that it resolves std::string to __cxx1112basic_stringIcSt11char_traits in both the cases.

I have a legacy library compiled with gcc 4.4.7 and takes string/std::map arguments and if my application compiled with gcc 5.4.0 and with c++98 flag on tries to link with that library i run into linker error, as the legacy library is not able to understand c++11 string.

Should't gcc resolve std::string to c++98 string.? or 5.4.0 has stopped supporting c++98 and is not backward compatible?
Comment 1 Jonathan Wakely 2018-05-04 09:53:07 UTC
This is behaving as intended, read https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html for details.
Comment 2 Sagar Shah 2018-05-04 10:04:49 UTC
thanks for your prompt response.