Skip to content

Commit 8506376

Browse files
committed
CPP: Examples Declaration.qll.
1 parent 3e46494 commit 8506376

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

cpp/ql/src/semmle/code/cpp/Declaration.qll

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,19 @@ abstract class Declaration extends Locatable, @declaration {
210210
}
211211

212212
/**
213-
* A C/C++ declaration entry. See the comment above `Declaration` for an
214-
* explanation of the relationship between `Declaration` and
215-
* `DeclarationEntry`.
213+
* A C/C++ declaration entry. For example the following code contains five
214+
* declaration entries:
215+
* ```
216+
* extern int myGlobal;
217+
* int myVariable;
218+
* typedef char MyChar;
219+
* void myFunction();
220+
* void myFunction() {
221+
* // ...
222+
* }
223+
* ```
224+
* See the comment above `Declaration` for an explanation of the relationship
225+
* between `Declaration` and `DeclarationEntry`.
216226
*/
217227
abstract class DeclarationEntry extends Locatable {
218228
/** Gets a specifier associated with this declaration entry. */
@@ -285,8 +295,19 @@ abstract class DeclarationEntry extends Locatable {
285295
* A declaration that can potentially have more C++ access rights than its
286296
* enclosing element. This comprises `Class` (they have access to their own
287297
* private members) along with other `UserType`s and `Function` (they can be
288-
* the target of `friend` declarations).
289-
*
298+
* the target of `friend` declarations). For example `MyClass` and
299+
* `myFunction` in the following code:
300+
* ```
301+
* class MyClass
302+
* {
303+
* public:
304+
* ...
305+
* };
306+
*
307+
* void myFunction() {
308+
* // ...
309+
* }
310+
* ```
290311
* In the C++ standard (N4140 11.2), rules for access control revolve around
291312
* the informal phrase "_R_ occurs in a member or friend of class C", where
292313
* `AccessHolder` corresponds to this _R_.
@@ -420,8 +441,19 @@ abstract class AccessHolder extends Declaration {
420441
/**
421442
* A declaration that very likely has more C++ access rights than its
422443
* enclosing element. This comprises `Class` (they have access to their own
423-
* private members) along with any target of a `friend` declaration.
424-
*
444+
* private members) along with any target of a `friend` declaration. For
445+
* example `MyClass` and `friendFunction` in the following code:
446+
* ```
447+
* class MyClass
448+
* {
449+
* public:
450+
* friend void friendFunction();
451+
* };
452+
*
453+
* void friendFunction() {
454+
* // ...
455+
* }
456+
* ```
425457
* Most access rights are computed for `DirectAccessHolder` instead of
426458
* `AccessHolder` -- that's more efficient because there are fewer
427459
* `DirectAccessHolder`s. If a `DirectAccessHolder` contains an `AccessHolder`,

0 commit comments

Comments
 (0)