mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-18 13:14:40 +03:00
Merge branch 'master' into bs-local-1
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
February 11, 2017
|
February 11, 2017
|
||||||
|
|
||||||
|
|
||||||
Editors:
|
Editors:
|
||||||
|
|
||||||
* [Bjarne Stroustrup](http://www.stroustrup.com)
|
* [Bjarne Stroustrup](http://www.stroustrup.com)
|
||||||
@@ -6690,11 +6691,49 @@ This a relatively rare use because implementation can often be organized into a
|
|||||||
|
|
||||||
##### Reason
|
##### Reason
|
||||||
|
|
||||||
???
|
Without a using declaration, member functions in the derived class hide the entire inherited overload sets.
|
||||||
|
|
||||||
##### Example
|
##### Example, bad
|
||||||
|
|
||||||
???
|
#include <iostream>
|
||||||
|
class B {
|
||||||
|
public:
|
||||||
|
virtual int f(int i) { std::cout << "f(int): "; return i; }
|
||||||
|
virtual double f(double d) { std::cout << "f(double): "; return d; }
|
||||||
|
};
|
||||||
|
class D: public B {
|
||||||
|
public:
|
||||||
|
int f(int i) override { std::cout << "f(int): "; return i+1; }
|
||||||
|
};
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
D d;
|
||||||
|
std::cout << d.f(2) << '\n'; // prints "f(int): 3"
|
||||||
|
std::cout << d.f(2.3) << '\n'; // prints "f(int): 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
##### Example, good
|
||||||
|
|
||||||
|
class D: public B {
|
||||||
|
public:
|
||||||
|
int f(int i) override { std::cout << "f(int): "; return i+1; }
|
||||||
|
using B::f; // exposes f(double)
|
||||||
|
};
|
||||||
|
|
||||||
|
##### Note
|
||||||
|
|
||||||
|
This issue affects both virtual and non-virtual member functions
|
||||||
|
|
||||||
|
For variadic bases, C++17 introduced a variadic form of the using-declaration,
|
||||||
|
|
||||||
|
template <class... Ts>
|
||||||
|
struct Overloader : Ts... {
|
||||||
|
using Ts::operator()...; // exposes operator() from every base
|
||||||
|
};
|
||||||
|
|
||||||
|
##### Enforcement
|
||||||
|
|
||||||
|
Diagnose name hiding
|
||||||
|
|
||||||
### <a name="Rh-final"></a>C.139: Use `final` sparingly
|
### <a name="Rh-final"></a>C.139: Use `final` sparingly
|
||||||
|
|
||||||
@@ -11795,12 +11834,12 @@ Static tools often have many false positives and run-time tools often have a sig
|
|||||||
We hope for better tools.
|
We hope for better tools.
|
||||||
Using multiple tools can catch more problems than a single one.
|
Using multiple tools can catch more problems than a single one.
|
||||||
|
|
||||||
Help the tools:
|
There are other ways you can mitigate the chance of data races:
|
||||||
|
|
||||||
* less global data
|
* Avoid global data
|
||||||
* fewer `static` variables
|
* Avoid `static` variables
|
||||||
* more use of stack memory (and don't pass pointers around too much)
|
* More use of value types on the stack (and don't pass pointers around too much)
|
||||||
* more immutable data (literals, `constexpr`, and `const`)
|
* More use of immutable data (literals, `constexpr`, and `const`)
|
||||||
|
|
||||||
### <a name="Rconc-data"></a>CP.3: Minimize explicit sharing of writable data
|
### <a name="Rconc-data"></a>CP.3: Minimize explicit sharing of writable data
|
||||||
|
|
||||||
@@ -12432,7 +12471,8 @@ Thread creation is expensive.
|
|||||||
// process
|
// process
|
||||||
}
|
}
|
||||||
|
|
||||||
void master(istream& is)
|
void
|
||||||
|
(istream& is)
|
||||||
{
|
{
|
||||||
for (Message m; is >> m; )
|
for (Message m; is >> m; )
|
||||||
run_list.push_back(new thread(worker, m));
|
run_list.push_back(new thread(worker, m));
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
'
|
'
|
||||||
0xFF0000
|
0xFF0000
|
||||||
0b0101'0101
|
0b0101'0101
|
||||||
|
10x
|
||||||
'14
|
'14
|
||||||
|
20x
|
||||||
2D
|
2D
|
||||||
2K
|
2K
|
||||||
2ndEdition
|
2ndEdition
|
||||||
@@ -69,6 +71,7 @@ CComPtr
|
|||||||
cerr
|
cerr
|
||||||
chrono
|
chrono
|
||||||
cin
|
cin
|
||||||
|
Clang's
|
||||||
class'
|
class'
|
||||||
clib
|
clib
|
||||||
Cline99
|
Cline99
|
||||||
@@ -492,6 +495,7 @@ toolchains
|
|||||||
TotallyOrdered
|
TotallyOrdered
|
||||||
TP
|
TP
|
||||||
tradeoff
|
tradeoff
|
||||||
|
TSAN
|
||||||
TSs
|
TSs
|
||||||
tt
|
tt
|
||||||
typeid
|
typeid
|
||||||
|
|||||||
Reference in New Issue
Block a user