one-definition-rule Questions

3

Solved

in visual studio you can set different compiler options for individual cpp files. for example: under "code generation" we can enable basic runtime checks in debug mode. or we can change the floatin...

2

The description of the std::set container given by cppreference.com contains this note at the end: The member types iterator and const_iterator may be aliases to the same type. Since iterator is...
Obscurant asked 21/6, 2019 at 9:59

1

The ODR allows us to define several times the same inline function (with some restrictions). However, what about the simpler case of static functions? // First TU static int foo() { return 0; } i...
Scintilla asked 9/5, 2019 at 16:39

2

Solved

According to Sergey Ryazanov, his Impossibly Fast C++ Delegates are not comparable: My delegates cannot be compared. Comparison operators are not defined because a delegate doesn't contain a poi...
Mutism asked 6/10, 2009 at 17:14

4

Solved

Citing C++ Draft N4713: Every program shall contain exactly one definition of every non-inline function or variable that is odr-used in that program outside of a discarded statement (9.4.1); n...
Warhol asked 8/2, 2019 at 14:17

1

Solved

Consider the following header and assume it is used in several TUs: static int x = 0; struct A { A() { ++x; printf("%d\n", x); } }; As this question explains, this is an ODR violation and, ...
Seldan asked 15/12, 2018 at 15:32

2

Solved

This question arised in the context of this answer. As I would expect, this translation unit does not compile: template <int Num> int getNum() { return Num; } template int getNum<0>()...
Kyser asked 5/10, 2018 at 11:3

2

Solved

If I have a header foo.h which I include all over my project, it seems to work fine when all it contains is: template<typename T> void foo(const T param) { cout << param << endl...

2

Solved

Let's consider some synthetic but expressive example. Suppose we have Header.h: Header1.h #include <iostream> // Define generic version template<typename T> inline void Foo() { std:...
Jacqui asked 15/7, 2017 at 16:20

1

Solved

Why does emplace_back take a reference of the member that requires a definition? What is the difference between emplace_back(integer literal) and emplace_back(static constexpr integer member)? If ...
Collinsworth asked 27/5, 2018 at 5:43

2

Solved

The code below compiles in GCC, clang and VS2017 and the expression a->i in the return statement is replaced by its constant value 1. Is it correct to say that this is valid because a is not odr...
Chub asked 19/5, 2018 at 18:31

1

This has come up on a couple of libraries I work with regularly. See, for example: Error SSL archive symbol table (run ranlib) no archive symbol table (run ranlib) while building libcryptopp.a th...
Dactylology asked 31/3, 2016 at 17:35

0

I have a Rust executable which was compiled purely within the Rust ecosystem; no external C code or linked libraries, sans whatever the compiler drags in. After compiling it with ASAN on Linux, AS...
Frydman asked 8/2, 2018 at 7:12

1

Solved

From the N4720 C++ Modules draft, [basic.def.odr]/6 says: […] For an entity with an exported declaration, there shall be only one definition of that entity; a diagnostic is required only if the ...
Escharotic asked 7/2, 2018 at 14:7

2

Solved

For example a.h class Dummy { public: Dummy() { std::cout << "a.h" << std::endl; } }; b.h class Dummy { public: Dummy() { std::cout << "b.h" << std::endl; } }; c.cc...
Concert asked 25/12, 2017 at 11:9

2

Solved

According to [temp.spec]/5: For a given template and a given set of template-arguments, ... an explicit specialization shall be defined at most once in a program (according to [basic.def.odr]), ...
Fanatical asked 29/11, 2017 at 2:56

1

Solved

If I pass an empty variable by value, even though it has no definition, is it safe and compliant? I came across this issue while working on code, overloading |, to make this print the contents of ...
Pluton asked 2/11, 2017 at 11:7

5

Solved

I have read materials below: https://www.wikiwand.com/en/One_Definition_Rule http://en.cppreference.com/w/cpp/language/definition What is the difference between a definition and a declaration? ...
Stercoraceous asked 28/10, 2017 at 9:15

2

Solved

I have a Config class // config.hpp class Config { public: static constexpr int a = 1; static constexpr int b = 1; } and include in main.cpp // main.cpp #include "config.hpp" int main () { ...
Sharla asked 13/10, 2017 at 3:24

1

I know that template functions don't suffer of multiple definitions when linking, like member functions defined inside a class, which are inline by default. Also, constexpr objects have internal li...
Orthohydrogen asked 21/9, 2017 at 5:13

1

Solved

If I have a header foo.h which contains #ifndef FOO_H_ #define FOO_H_ namespace foo { constexpr std::string_view kSomeString = "blah"; } #endif // FOO_H_ then is it safe to include foo.h from ...
Neruda asked 14/8, 2017 at 0:28

3

Solved

Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Optimizations aside, what happens whe...

2

Solved

This just came up in the context of another question. Apparently member functions in class templates are only instantiated if they are odr-used. Could somebody explain what exactly that means. The ...
Crone asked 28/10, 2013 at 8:58

1

On reading code online from production libraries I found something like this Traits.hpp template <typename Type> class Traits { template <typename T, detail::EnableIfIsInstantiation&...
Carrara asked 10/6, 2017 at 20:49

1

Solved

This program prints 1 1 instead of 1 2 when compiled with MSVC (up to VS 2015). f1.cpp: #include <functional> static std::function<int ()> helper() { struct F { int operator()() { r...
Doorsill asked 5/11, 2015 at 12:50

© 2022 - 2024 — McMap. All rights reserved.