Questions tagged [cpp-core-guidelines]

The C++ Core Guidelines are a collaborative effort led by Bjarne Stroustrup, much like the C++ language itself. They are the result of many person-years of discussion and design across a number of organizations. Their design encourages general applicability and broad adoption but they can be freely copied and modified to meet your organization's needs.

The C++ Core Guidelines, managed from this GitHub repository, represent a recent attempt to define good practices for modern C++ development. The guidelines focus on rules which static analysis tools are capable of detecting.

Alongside the guidelines themselves is the guideline support library (GSL). While the guidelines do not go into explicit detail about the behavior of such features, the Microsoft implementation currently acts as the de-facto standard.

94 questions
1
vote
1 answer

Meaning of f(T*, int) interfaces vs. f(span) interfaces in core cpp guidelines

Section P3 of the core cpp guidelines offers up the following pattern under its enforcement section: f(T*, int) interfaces vs. f(span) interfaces Can anyone explain what it means to a crusty old C programmer looking to understand modern C++?
Joe
  • 7,378
  • 4
  • 37
  • 54
1
vote
0 answers

CPPCoreGuidelines span for a T** interface?

In digital signal processing audio is commonly passed around as a 2D array of channels and samples i.e. void use(float** buffer, int channels, int samples) { ... } A lot of libraries I use expect this format. In terms of my own code, for safer…
1
vote
2 answers

Initialized priority variable in class and cpp core guidelines?

I have use C++ Core Checker nuget and run my code analyst I have this warning warning C26495: Variable 'Point::_x' is uninitialized. Always initialize a member variable. (type.6: http://go.microsoft.com/fwlink/p/?LinkID=620422) Point.h class…
NinjaDeveloper
  • 1,620
  • 3
  • 19
  • 51
1
vote
1 answer

How to use C++ Core Checker in Unreal Engine project?

Here is an instruction how to use C++ Core Checker: C++ Core Guidelines Checkers available for VS 2015 Update 1. I installed NuGet package successfully, but cannot use/enable it. There are no options related to static analysis in Property Pages of…
0
votes
2 answers

Is gsl::owner usable for shared-ownership?

For example, can it be used in Qt for the following? gsl::owner w{new QWidget{parent}} In this example, the ownership is shared by the new-site and the parent, because the code who has new-ed the object can delete w, and W's destructor…
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
0
votes
1 answer

Expressing ideas directly in code - what does the definition mean?

Im new to c++, I'm reading the core guidelines and I came across this: P.1: Express ideas directly in code In this, it says to use something like Month month() const; instead of int month(); So I have 2 questions, why is there a const at the end of…
Johnathon
  • 165
  • 1
  • 1
  • 6
0
votes
1 answer

How do I define __cpp_exceptions for gsl:narrow to compile?

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 #include to my stdafx.h file. But the gsl:narrow…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
0 answers

About using directives in namespace in header files

(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 using namespace in a non-global namespace can be…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
1 answer

Why do C++ regular expression functions use output parameters?

Output parameters in C++ are generally considered a code smell according to the core guidelines. Yet, we have such functions in the regular expressions library template< class BidirIt, class Alloc, class CharT, class Traits > bool…
0
votes
0 answers

C++ Core Guidelines: Lifetime - why does the following code trigger a warning?

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. Parameter 0 '@vA' in call to…
user3768612
  • 101
  • 1
  • 1
  • 4
0
votes
1 answer

Error Handling with Core Guidelines GSL Expects, Ensures, and narrow_cast

I am trying to follow the Cpp Core Guidelines and use GSL where appropriate. In particular, I would like to use Expects and Ensures for pre and post-conditions, as well as span, and narrow_cast, but the error handling is not robust and does not…
Phil
  • 5,822
  • 2
  • 31
  • 60
0
votes
2 answers

Assert is seen as C style cast in Visual Studio

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 Guidelines. However, since I activated these options…
Razvanip
  • 23
  • 1
  • 8
0
votes
1 answer

How to "reset" gsl::owner?

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, among them do not use new and delete directly,…
Simon Richter
  • 28,572
  • 1
  • 42
  • 64
0
votes
0 answers

Disparity between the std::deque and std::vector range constructors

This doesn't generate any warning at all and works as expected. vector vec_2(1024, -3.0f); vector vec_3(vec_2.begin(), vec_2.end()); This, however, generates C26486 "Don't pass a pointer that may be invalid as a parameter to a…
Big Temp
  • 434
  • 4
  • 12
0
votes
1 answer

Wasted space in layout in CPP Core Guidelines

I was reading CPP Core Guidelines, P.9: Don’t waste time or space: Example, Bad: struct X { char ch; int i; string s; char ch2; X& operator=(const X& a); X(const X&); }; Then it states: ... Note that the layout of X…
Moia
  • 2,216
  • 1
  • 12
  • 34