343 questions
Score of 9
1 answer
657 views
Do different name lookup trajectories violate ODR?
Assume there are two translation units that differ only in the name of one namespace: aggregator_1 vs. aggregator_2:
// Translation unit 1
namespace a {
struct Point
{
int x;
int ...
Score of 4
1 answer
142 views
ODR and namespaces/scope
The one definition rule in the C++20 standard states that there can be no two definitions of a class type in a program unless the two definitions are in different translation units and have the same ...
Score of 5
2 answers
178 views
How to cause a linker error when an externally-defined macro is inconsistent across translation units?
I'm writing a header-only library which defines class X in header x.hpp. The implementation of X is different for different standard versions:
#if __cplusplus < 201703
class X {
int a; ...
Score of 5
1 answer
177 views
Is an "inline function template" considered a "inline function" with respect to ODR rules?
In the C++20 draft (N4868) there are two relevant rules about definition reachability:
Inline functions must have their definition reachable in every translation unit in which they are ODR-used:
[...
Score of 4
2 answers
172 views
If a declaration with an initializer is always a definition, why isn't the declaration of a static const member variable a definition?
In The C++ Programming Language 4th edition, in §6.3, page 153, I read
Any declaration that specifies a value is a definition
Again, in §15.2, page 421,
a declaration with an initializer is always ...
Score of 6
1 answer
126 views
Deleting a file scope function in a header file
I am writing a header file, in which there is a void Foo() function in file scope, and I want it to be deleted. Should it be inline?
void Foo() = delete;
or
inline void Foo() = delete;
Score of 5
2 answers
336 views
How does ODR work with lambdas at global scope
I have the following code -
template <typename T, typename F>
struct unique {};
template <auto F>
struct ltype {
using type = decltype(F);
};
using p = unique<int, ltype<[](){}&...
Score of 0
1 answer
266 views
Discarded-value expression and odr-used in C++20
Consider the following example:
#include <iostream>
using namespace std;
int main() {
int n=1;
[]()
{
n;// (1): error
}...
Score of 14
4 answers
258 views
Wrong constructor being called causes segmentation fault
I have two classes that are independently declared in their own header and have their methods defined in their own TUs /.cpp's.
the classes are the same name-wise and namespace-wise, but exist in ...
Score of 0
1 answer
84 views
ODR-use a member function of a template class only if it is valid
I need to define a member function __say_hi on a class template, which will not be called anywhere, but still need to be kept by my clang-based frontend. To do so, I add a constexpr static member ...
Score of 0
0 answers
98 views
Multiple symbol definitions when using the same template type from different DLLs used in the same project
I have a hard problem with multiple definitions of symbols in a complicated environment I do not completely control.
I apologise in advance for the verbosity of the question... but it's quite ...
Score of 2
0 answers
74 views
Problem with ambiguity of functions from different libraries - multiple CMakeLists.txt?
I'm working on a project, with CMake, that uses mainly two different libraries:
ROOT: https://root.cern/
OpenCASCADE: https://dev.opencascade.org/
When I try compiling I get errors of ambiguity. ...
Score of 2
1 answer
138 views
Are multiple identical non-inline constexpr variable definitions allowed in different translation units in C++23?
C++23 says that constexpr functions and static data members are implicitly inline, but it does not say the same for namespace-scope constexpr variables. It also says that: "For any definable ...
Score of 1
1 answer
179 views
Does C++23 allow multiple definitions of a namespace-scope non-inline variable in different translation units?
In old versions of C++, such as C++17, the one-definition rule was intuitive at a high-level in that it allowed only one definition of variables
Every program shall contain exactly one definition of ...
Score of 3
1 answer
102 views
How does the ODR interact with "unique" types that use a non-type template defaulted to a lambda expression?
If a class template uses a lambda a default template argument, every default usage of that class type will be a new type.
template <auto unique = [] {}>
struct UniqueStruct {};
static_assert(!...