What are some common bad C++ practices in the tech industry?

One thing is meyers singleton is sometimes marked static where it usually should not: https://stackoverflow.com/questions/1661529/is-meyers-implementation-of-the-singleton-pattern-thread-safe , mostly it should be marked inline instead.

if this is included in more than one TU than each TU will gets its own instance of instance() and therefore its own instance of Singleton:

//static_local_source.hpp
#pragma once

namespace static_local_source {
        static int& static_local_source (){
                static int i {};
                return i;
        }
}

//tu_a.hpp
#pragma once
#include "static_local_source.hpp"

namespace tu_a {
        void increment_static_local();
        int & get_static_local();
}
//tu_a.cpp
#include "tu_a.hpp"
namespace tu_a {
        void increment_static_local(){
                ++static_local_source::static_local_source();
        }
        int & get_static_local(){
                return static_local_source::static_local_source();
        }
}

//tu_b.hpp
#pragma once
#include "static_local_source.hpp"

namespace tu_b {
        void increment_static_local();
        int & get_static_local();
}
//tu_b.cpp
#include "tu_b.hpp"
namespace tu_b {
        void increment_static_local(){
                ++static_local_source::static_local_source();
        }
        int & get_static_local(){
                return static_local_source::static_local_source();
        }
}

 //main.cpp                                         
#include"tu_a.hpp"
#include"tu_b.hpp"

#include<iostream>

int main(){
        auto & a = tu_a::get_static_local();
        auto & b = tu_b::get_static_local();

        std::cout << "a: " << a << " ; b: " << b << '\n'; // a = 0, b = 0
        tu_a::increment_static_local();
        std::cout << "a: " << a << " ; b: " << b << '\n'; //a = 1, b = 0, would be a = 1 b = 1 if we used proper (extern linkage) singleton
        tu_b::increment_static_local();
        std::cout << "a: " << a << " ; b: " << b << '\n'; //a = 1, b = 1, would be a = 2 b = 2 as above

        return 0;
}
/r/cpp_questions Thread