Skip to main content
Filter by
Sorted by
Tagged with
6 votes
2 answers
277 views

When I have some const members variables in my class, I would like to know how to respect core guideline C.12 to keep a default copy-assignment operator. C.12: Don’t make data members const or ...
kingsjester's user avatar
3 votes
1 answer
260 views

There is the following C++ Core Guideline: Header files should be self-contained In large project, how can we automate this check, I would like to avoid having to add empty .cpp files for every &...
darune's user avatar
  • 11.5k
2 votes
1 answer
166 views

Consider the following code: #include <string> auto f1(auto&& v) { return v; } auto f2(auto&& v) { return std::forward<decltype(v)>(v); } int main() { return ...
xmllmx's user avatar
  • 44.6k
2 votes
1 answer
173 views

Cpp Core Guideline F19 tells us Flag a function that takes a TP&& parameter (where TP is a template type parameter name) and does anything with it other than std::forwarding it exactly once ...
pasbi's user avatar
  • 2,191
-3 votes
1 answer
363 views

C++ Core Guidelines, I.3: Avoid singletons: Exception You can use the simplest “singleton” (so simple that it is often not considered a singleton) to get initialization on first use, if any: X& ...
3CEZVQ's user avatar
  • 42.9k
4 votes
1 answer
379 views

For code like this: #include <cstdint> extern const char *f(); extern void g(const uint8_t *); int main() { const char *p = f(); g(reinterpret_cast<const uint8_t *>(p)); } clang-...
user1244932's user avatar
  • 8,282
1 vote
1 answer
1k views

In the C++ Core Guidelines std::optional is only referred once: If you need the notion of an optional value, use a pointer, std::optional, or a special value used to denote “no value.” Other than ...
Henk's user avatar
  • 866
1 vote
1 answer
344 views

I have a function like this: void column(const std::string &value) { ... } void column(float value) { ... } template <class... TColumns> void row(const TColumns &...columns) { ImGui::...
Gasim's user avatar
  • 8,051
2 votes
1 answer
1k views

disclaimer: this question is about prevention of unintended naming collisions, and make sure the following code fail to compile/link. [edit] actually I'd be happy with something preventing this to ...
ThreeStarProgrammer57's user avatar
1 vote
1 answer
621 views

I am getting confused again :( I have looked at this discussion: detect at compile time whether exceptions are disabled I am new to trying to use GSL. I have copied the GSL folder to my PC and added a ...
Andrew Truckle's user avatar
0 votes
0 answers
37 views

(This is kind of related to a previous question.) Core guideline SF.7 gives a good motivation for avoiding to put using namespace directives at global scope in a header file. However, even writing ...
Enlico's user avatar
  • 30.2k
4 votes
2 answers
382 views

With the guideline support library and utilities like gsl_Expects C++ implements contracts for the time being (there are plans to bake this stuff into the language in the future). Using this feature ...
Lorah Attkins's user avatar
1 vote
0 answers
315 views

When compiling the following code in Visual Studio 2019 while using the "C++ Core Check Lifetime Rules", I get warning C26486: Don't pass a pointer that may be invalid to a function. ...
user3768612's user avatar
-1 votes
1 answer
242 views

Which is the recommended order in which the #include directives are supposed to be listed? I could not find any answer in the C++ Core Guidelines For example, should they be ordered like this: #...
nyarlathotep108's user avatar
2 votes
0 answers
2k views

I'm getting a clang-tidy warning that reads narrowing conversion from 'int' to 'float' when I convert from a uint8_t to a float, which to my understanding is not a narrowing conversion since float can ...
mt_xing's user avatar
  • 684
16 votes
3 answers
6k views

I have a private static vector in my class that keeps a pointer to all objects created from it. It's necessary as each object needs access to information from all the other objects to perform some ...
M47's user avatar
  • 471
6 votes
4 answers
2k views

Motivation The C++ Core Guidelines recommends using dynamic_cast when "class hierarchy navigation is unavoidable." This triggers clang-tidy to throw the following error: Do not use ...
user1032677's user avatar
5 votes
2 answers
235 views

I am reading this recently, which states: Don’t assume that complicated code is necessarily faster than simple code. The code is copied as following: Example, good // clear expression of intent, ...
rustyhu's user avatar
  • 2,235
10 votes
1 answer
11k views

When I use the following code, I get a warning (From applying cppcoreguideline). Code: SampleClass *object = nullptr; object = new SampleClass(); Warning: warning: assigning newly created 'gsl::...
Ravi's user avatar
  • 309
0 votes
2 answers
443 views

Here is the error and a glimpse of the code One of my courses demands me to use Warning Level 4 and to treat warnings as errors in Visual Studio. Beside that, we also need to activate Cpp Core ...
Razvanip's user avatar
0 votes
1 answer
2k views

When I create an object and append it to a list auto o = new object; m_objects.push_back(o); I get several hints from the compiler that I should clean up my code along the C++ Core Check guidelines, ...
Simon Richter's user avatar
1 vote
1 answer
215 views

I activated static analysis for my project in Visual Studio. The Core Guidelines checker says i should use gsl::at for subscription. But my code is save. What's the cleanest way to get rid of this ...
Martin Fehrs's user avatar
  • 1,165
3 votes
1 answer
438 views

I am using lambdas to initialize some const variables as described in the core c++ guidelines here. In short, the idiom looks like this const auto a = [&]() { MyType a; // complex ...
patatahooligan's user avatar
4 votes
1 answer
2k views

Clang-tidy's cppcoreguidelines-pro-type-union-access rule is essentially a complete ban on unions, it flags all access to union members. My library has an extern "C" interface with a structure which ...
Calmarius's user avatar
  • 19.7k
13 votes
2 answers
1k views

Triggered by this answer I was reading in the core guidelines: C.45: Don’t define a default constructor that only initializes data members; use in-class member initializers instead The reasoning ...
463035818_is_not_an_ai's user avatar