one-definition-rule Questions
2
Solved
I was reading ODR and as the rule says "In the entire program, an object or non-inline function cannot have more than one definition" and I tried the following...
file1.cpp
#include <iostream&...
Angelesangelfish asked 23/9, 2016 at 4:55
2
Solved
I've picked up the habit to always enclose types defined in source files in unnamed namespaces because I know they can cause ODR violations:
// my_source.cpp
namespace {
struct MyStruct {};
}
Wha...
Vile asked 11/12, 2023 at 16:15
3
Solved
I'm having a rather strange problem telling googletest to print a certain class the way I want using PrintTo.
The class is a very simple 2D point, it is in a namespace and the PrintTo function is i...
Tantalum asked 10/7, 2014 at 9:55
2
Solved
What exactly does the One-Definition Rule in C++ say?
The only trustworthy occurrence I can find is in The C++ Programming Language, 3rd. ed., P. 9.2.3. Is there any official definition of the rule...
Skipjack asked 16/11, 2010 at 8:9
4
Solved
If I include <string> or <vector> in multiple translation units (different .cpp files), why doesn't it break the ODR?
As far as I know, each .cpp is compiled differently, so std::vector...
Sanguine asked 31/12, 2015 at 23:23
1
Solved
Every year or two I decide to try out using C++ modules, but every time I run into issues, usually with the compiler. But this time my issue seems to be in the specification itself, and I can't see...
Kaffraria asked 7/8, 2023 at 8:7
1
Consider this program in three files:
// a.h
#include<iostream>
constexpr auto f() {
int i = 0;
auto l1 = [](int& j) { return ++j; };
auto l2 = [](int& j) { return j*=2; };
ret...
Mcdaniel asked 19/4, 2020 at 8:52
1
Solved
When a range based for loop is used to iterate over an array, without binding a reference to each element, does this constitute an ODR-use of the array?
Example:
struct foo {
static constexpr int ...
Interplay asked 26/5, 2022 at 3:31
1
Solved
Is use in a default member initializer still an odr-use, even if the default member initializer is not used by any constructor?
For example, is this program ill-formed because g<A> is odr-use...
Navigable asked 9/3, 2022 at 11:36
2
So for example, I have a slightly complicated case of library dependency in one of my projects:
/--------------------------------\
| |
/----> GRPC <------------------\ |
| | |
| (c++) |...
Obtest asked 30/12, 2021 at 6:56
16
Solved
When should I write the keyword inline for a function/method in C++?
After seeing some answers, some related questions:
When should I not write the keyword 'inline' for a function/method in C++?...
Hejira asked 18/11, 2009 at 21:46
3
Solved
The setup
If I have a program like this
A header file that declares my main library function, primary() and defines a short simple helper function, helper().
/* primary_header.h */
#ifndef _PRI...
Liebig asked 4/3, 2018 at 20:18
3
Suppose you have the following definition of a C++ class:
class A {
// Methods
#ifdef X
// Hidden methods in some translation units
#endif
};
Is this a violation of One Definition Rule for the cla...
Terrific asked 4/2, 2021 at 6:47
1
Solved
If I have: a.hpp a.cpp and main.cpp includes a.hpp, and in a.hpp I write
template<typename T>
constexpr int num;
template<>
constexpr int num<float> = 1;
template<>
constexp...
Syllable asked 31/12, 2020 at 12:39
1
Solved
Consider a templated entity, say (A) a function template, and (B) a member enum of a class template.
// (A)
template<auto>
int f();
// (B)
template <auto>
struct T { enum class E; };
...
Pearly asked 27/11, 2020 at 17:50
1
Solved
I'm working on a project which has a "util" library containing stuff like logging, assertion handling etc. This is compiled into a static library with -fPIC added. I also have a plugin sy...
Joint asked 7/8, 2019 at 8:58
3
I'm working on a codebase which uses the following structure:
a.h:
template<int N> void f();
void b();
a.cpp:
#include "a.h"
template<> void f<1>() {}
int main()
{
b...
Interpose asked 11/4, 2020 at 1:10
1
Solved
The following code defines the entire program. Is this program standard conformant (with the latest version)?
void foo();
int main()
{
auto x = &foo;
return 0;
}
Here is a convenience sho...
Carpology asked 1/4, 2020 at 18:46
1
Solved
Let's say I have 2 TUs with 2 non-inline function definitions with external linkage which differ only in their return types.
Which paragraph(s) my program violates?
[basic.def.odr]/4 says:
Every...
Phototopography asked 25/2, 2020 at 20:11
6
In C and C++, you can't have a function with two definitions. For example, say we have the following two files:
1.c:
int main(){ return 0;}
2.c:
int main(){ return 0;}
Issuing the command gcc 1.c...
Vociferant asked 5/2, 2020 at 23:13
0
I have come across a situation in our codebase where two DLLs that link to each other, both link statically to the same static library. This results in both DLLs pulling in a separate copy of the s...
Eroticism asked 8/11, 2019 at 15:25
2
While thinking about this question, I stumbled upon something else I don't understand.
Standard says...
[class.dtor]/4
If a class has no user-declared destructor, a destructor is implicitl...
Tetramethyldiarsine asked 24/10, 2019 at 14:10
3
Solved
I am trying to dig into implications of a function being inline and stumbled upon this issue. Consider this small program (demo):
/* ---------- main.cpp ---------- */
void other();
constexpr int ...
Ebarta asked 18/10, 2019 at 14:35
3
I have only just started learning C++, and I see that functions are usually declared and defined separately, for example:
// Declaration
void sayhi(std::string name);
// Definition
void say...
Brooksbrookshire asked 12/9, 2019 at 11:28
2
Solved
I'm getting a strange behavior which I don't understand. So I have two different classes with the same name defined in two different cpp files. I understand that this will not cause any error durin...
Letterhead asked 15/8, 2019 at 21:55
1 Next >
© 2022 - 2024 — McMap. All rights reserved.