Commit Graph

1758 Commits (For-1446)
 

Author SHA1 Message Date
hsutter fcb2960793 Closes #1446
This PR affirms that all virtual functions, *including destructors*,
should be declared exactly one of `virtual`, `override`, or `final`, and
takesa pass through the document to make the examples and guidance
consistent with that.

Of course a virtual destructor is a virtual function: It behaves
polymorphically, and it has a vtable entry that can be overwritten ==
overridden in a derived class exactly the same as any other derived
virtual override. See also [class.virtual]/7: "Even though destructors
are not inherited, a destructor in a derived class overrides a base
class destructor declared virtual; see [class.dtor] and [class.free]."

However, the following exception text currently appears in C.128:

> If a base class destructor is declared `virtual`, one should avoid
declaring derived class destructors  `virtual` or `override`. Some code
base and tools might insist on `override` for destructors, but that is
not the recommendation of these guidelines.

... but this exception is (a) not well-founded, and (b) inconsistent
with the Guidelines' practice in other examples and with the rationale a
few lines earlier for C.128 itself.

Re (a):

- The exception is overly broad: The rationale given for this exception
is entirely against marking destructors `override` (not `virtual`). So
clearly the exception to write neither keyword is too broad: At most,
the exception should be to write `virtual` rather than `override`.
- Explicit `virtual` is primarily for class users, not class authors:
The arguments given in #721 favoring this exception are from the
viewpoint of the implementation of the function (even then, the
arguments are debatable and debated). But `virtual`, `override`, and
`final` are primarily for the far larger audience of *class users and
call sites* of the function, for whom of course we should document each
declared function that is polymorphic, *especially* the destructor --
this tells calling code whether the function is safe to call through a
(smart or built-in) pointer or reference to base, which will nearly
always be the case for such types. We should not make the reader of the
code go way to look in the base classes to figure out whether a function
declared in this class is virtual or not -- the reason this Item exists
is primarily to avoid that implicit virtual antipattern via convention
and automated enforcement. For class users, all virtual functions
including destructors are equally polymorphic.

Re (b): The Guidelines already don't follow this. For instance, two
Items later (in C.130) we have this example that correctly uses
`override`:

~~~
virtual ~D() override;
~~~

... though per C.128 it should not also specify `virtual` (also fixed in
this PR).

Finally, the exception also contradicts the rationale given earlier in
the same Item.
7 years ago
beinhaerter 4b414458cf I.13: grammar and hint to `std::string_view` (#1443)
- "a C-style, zero-terminated strings" is wrong, it must be either "C-style, zero-terminated strings" or "a C-style, zero-terminated string"
- added hint to `std::string_view
7 years ago
beinhaerter 040ea419cc I.10: structured bindings is now available (#1442)
- C++17 is already available
- synchronize with F.21:
  - put quotes around "structured bindings"
  - remove link to proposal
7 years ago
Herb Sutter 8a707c5274
DO credit 7 years ago
Herb Sutter 5d65a37863
Added DO credit 7 years ago
alexcamposruiz 2d40c3ac2c Add example code for T.48 (#1422)
* Add example code for T.48

* Fix whitespace in end of line

* Use better syntax for concept constraint

* Revert "Use better syntax for concept constraint"

This reverts commit f071920d7f.
7 years ago
jkorinth 4c35d4c022 Fix C.120 good example (#1426)
C.120 has a good example which violates C.128 by specifying both virtual and override for methods.
closes #1425
7 years ago
Louis Cloete 6c92f514f4 Remove extra asterisk in example in C.60 (#1430)
closes #1429
7 years ago
Louis Cloete 29dedc49af Inserts a missing backtick in C.49 (#1428)
Below heading "Example, better still" there was a missing backtick after gsl::string_span
7 years ago
Sergey Zubkov dbc554cbc5 update date 7 years ago
Herb Sutter 9948bdc157
Update ES.23 to allow = initialiization (#1416)
* Update ES.23 to allow = initialiization

* Silencing Travis

* Changed title back to original, it's fine

* Add note about explicit
7 years ago
Dave Smith a9242c8dae Improve A.all (#1413)
* reword the A.1 rule title
* add candidate content for the A.1 rule
* make minor improvements to the A.2 note
* simplify wording in the first bullet of A.4's Reason
7 years ago
hsutter fc27313b75 Adopting fixes from PR 1411 7 years ago
hsutter 959b556aac Restored cached_computation description 7 years ago
Dave Smith 1a9a35d2d9 Tighten up CP.1 (#1405)
* Tighten up CP.1

* balanced verb usage in first sentence
* changed third sentence to "libraries not using threads", as I
  believe this was the original author's intended meaning.
* clarified "this" in fourth sentence
* cut wordiness of "thanks to the magic of cut-and-paste", as it
  added no value
* changed "Example" heading to "Example, bad"
* added "bad:" comment above statics in the example
* added an explanatory sentence immediately after the example
* changed "works perfectly in a single-threaded" after example to
  "works as intended in a single threaded".  Also balanced the
  structure of the two comma separated phrases inside this sentence.
* strengthened parenthetical explanation in second bullet of "could
  be made safe" section

* Correct grammar mistake pointed out by @cubbimew

* Remove specific cache details in CP.1 per @hsutter's request
7 years ago
hsutter 41b5bac211 Revert "Fixed typo in ES.22"
This reverts commit 976ee508a4.
7 years ago
hsutter 976ee508a4 Fixed typo in ES.22 7 years ago
Florian Thake 385199cc90 Added bad and good example to NR.5 in CppCoreGuidelines.md (#1401)
* Added bad and goof example to NR.5 in CppCoreGuidelines.md

Added bad and good example to NR.5 Don’t: Don’t do substantive work in a constructor; instead use two-phase initialization.
I think it could be suitable.

* adjusted coding style

* removed extra space

* removed one more whitespace

* removed spaces before note to make it a blank line

* made Cleanup method from bad example return void

* some changes after review comments

- removed try catch
- removed defaulted dtor
- changed int to size_t, removed check for even.
- Expects() for invariant check
- typo

* spell check adjustment

* moved comment up for met the line length

* changed variablename in good example

... they were named same after removed the try catch scope

* changed afer comments

- changed check_size() function to a static member function 
- fixed comment mentioning the default contract violation behavior.
7 years ago
Kyle 0f57785d2b C.129 Small fixes (#1406)
* C.129 Fix typos and conjugation

I noticed some grammatical errors in this section and fixed them to match my interpretation of the author's intention.

* One more fix

Pluralization
7 years ago
Aleksander 6a6321fcbf ES.49: added lvalue in std::forward description (#1404) 7 years ago
Aleksander 9f5a67fda7 ES.42: index in an example was not declared (#1403) 7 years ago
Paul Romano 1f6042f66c Fix typo in some of the NL rules, "thus rule" -> "this rule" (#1402) 7 years ago
hsutter 35cfe0c984 Closes #1397 7 years ago
hsutter 9275e7da09 Fixed typo in previous commit, closes #1395 7 years ago
hsutter 85e6aef5d6 Closes #1395 7 years ago
hsutter 274d65818d Closes #1392 7 years ago
hsutter 4b7cd81ad0 Closes #1392 7 years ago
Taewon Park 7ddf721500 Fix wrong <a> tags in Pro.bounds and Pro.lifetime (#1399)
Replaced "href" attribute to "name" of <a> tags in Pro.bounds and Pro.lifetime sections, to make the anchors to them work correctly
7 years ago
Sergey Zubkov 73f37745b1 fix typo 7 years ago
Saad 08659db9e1 MD typo fix (#1396) 7 years ago
hsutter c072184052 Closes #1370 7 years ago
hsutter 142fc6ad33 Closes #1367 7 years ago
Amir Livneh e3da8a1fd9 Add example for E.28 (#1385) 7 years ago
Dave Smith c2a5785d7e Remove elements that don't add value in ES.84 (#1390) 7 years ago
Dave Smith 8301421762 Tighten up the intro to CP (#1391) 7 years ago
Amir Livneh a8c7b7c5a8 Fix grammar in T.41 (#1389) 7 years ago
Amir Livneh bd3f3d5d25 Fix grammar in Con.2 (#1388) 7 years ago
Amir Livneh 422a190f57 Fix typo in T.22 (#1387) 7 years ago
Amir Livneh aa25be7d6b Make sentence in T.41 complete (#1386) 7 years ago
Amir Livneh ba2dbc5edf Fix calls to malloc() with 2 arguments (#1377)
* Fix calls to malloc() with 2 arguments
7 years ago
Amir Livneh f67e91d295 Use `memoizes` instead of `mnemonizes` in the context of caching (#1383)
* Use `memoizes` instead of `mnemonizes` in the context of caching

While apparently, 'mnemonizes' is a word, I don't think it's the best choice here.

* Update isocpp.dic
7 years ago
Amir Livneh c1beff1941 Fix grammar in T.11 (#1380) 7 years ago
Amir Livneh 43f4390185 Fix grammar in T.13 (#1379) 7 years ago
Amir Livneh 8ff099d2d2 Fix grammar (#1378) 7 years ago
Amir Livneh 1a3e4040fa Remove extra space from README (#1376) 7 years ago
Amir Livneh 7d092e37aa Remove extra parenthesis (#1375) 7 years ago
Amir Livneh 7511b40996 Use 'an' instead of 'a' where appropriate (#1374) 7 years ago
Amir Livneh 571ab494a8 Use consistent tense and remove repetition in E introduction (#1372) 7 years ago
Amir Livneh e93462e1d7 Fix capitalization in CP.200 (#1373) 7 years ago
Amir Livneh 6d94ce30dd Fix grammar in E.4 note (#1371) 7 years ago