0

I have to compile the code of tokumx from percona's github repository. It contains an ambiguity regarding the use of shared_ptr .

In short, the pattern is as follows:

namespace baz
{
    class integer;
}

namespace bar
{
    class integer;
}

namespace foo
{
    using namespace bar;
    using baz::integer;
}

namespace main
{
    using namespace foo;

    void f(const integer&);
}

Naturally, this won't compile. And I am not here to ask why, but rather to understand how this ever compiled in the first place and if I can trust that codebase at all. That code is from 2014 and C++11 was definitely a thing back then. My suspicion is that this code was never compiled with C++11 simply because the compilers did not default to that standard 5 years ago, is that correct?

  1. When (which gcc/clang version) was C++11 the default?
  2. Is there some magic compiler flag that would resolve the issue even with C++11?
  3. Now to the bonus question: If that software was never compiled with C++11 is it even safe to patch that particular spot or do I risk invisible changes in behavior that can lad to severe runtime errors? (By invisible I mean errors that do not occur at compile-time but rather changes in behavior that lead to errors at runtime like memory leaks or crashes.)
choeger
  • 3,562
  • 20
  • 33
  • `std::shared_ptr` didn't exist before C++11. – melpomene Jan 07 '19 at 08:38
  • I know. That's why I am asking when it became the default. – choeger Jan 07 '19 at 08:39
  • GCC 6.0 according to [this](https://stackoverflow.com/questions/21221411/when-will-gnu-c-support-c11-without-explicitly-asking-for-it). And Clang 6.0 also, according to [this](https://stackoverflow.com/questions/21581838/set-as-default-c11-in-clang). Clang 6.0.0 came out on 8th March 2018. (Although Clang was C++11 feature complete on 19 April 2013). – Duck Dodgers Jan 07 '19 at 08:40
  • 1
    C++11 is not the default in any GCC version. – melpomene Jan 07 '19 at 08:46
  • 1
    That's also why `using namespace std;` in header is **bad**. – Jarod42 Jan 07 '19 at 09:11
  • *"is it even safe to patch that particular spot"* Depends how you fix it, but qualify each `shared_ptr` should be safe (as you didn't mix them). Removing the `using namespace` might introduce subtle bug if there is an overload with better match in `std`. – Jarod42 Jan 07 '19 at 09:19

0 Answers0