Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5468b8d

Browse files
author
Matthew Gretton-Dann
committed
C++: Add support for C++ using aliases
Previously these were identified as typedefs.
1 parent 825a3d2 commit 5468b8d

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ private import semmle.code.cpp.internal.ResolveClass
33

44
/**
55
* A C/C++ typedef type. See 4.9.1.
6+
*
7+
* Represents either of the following typedef styles:
8+
*
9+
* * CTypedefType: typedef <type> <name>;
10+
* * UsingAliasTypedefType: using <name> = <type>;
611
*/
712
class TypedefType extends UserType {
8-
TypedefType() { usertypes(underlyingElement(this), _, 5) }
913

10-
override string getCanonicalQLClass() { result = "TypedefType" }
14+
TypedefType() {
15+
usertypes(underlyingElement(this),_,5) or
16+
usertypes(underlyingElement(this),_,14)
17+
}
1118

1219
/**
1320
* Gets the base type of this typedef type.
@@ -26,10 +33,6 @@ class TypedefType extends UserType {
2633
result = this.getBaseType().getPointerIndirectionLevel()
2734
}
2835

29-
override string explain() {
30-
result = "typedef {" + this.getBaseType().explain() + "} as \"" + this.getName() + "\""
31-
}
32-
3336
override predicate isDeeplyConst() { this.getBaseType().isDeeplyConst() } // Just an alias
3437

3538
override predicate isDeeplyConstBelow() { this.getBaseType().isDeeplyConstBelow() } // Just an alias
@@ -45,6 +48,34 @@ class TypedefType extends UserType {
4548
override Type stripType() { result = getBaseType().stripType() }
4649
}
4750

51+
/**
52+
* A traditional C/C++ typedef type. See 4.9.1.
53+
*/
54+
class CTypedefType extends TypedefType {
55+
56+
CTypedefType() {
57+
usertypes(underlyingElement(this),_,5)
58+
}
59+
60+
override string getCanonicalQLClass() { result = "CTypedefType" }
61+
62+
override string explain() { result = "typedef {" + this.getBaseType().explain() + "} as \"" + this.getName() + "\"" }
63+
}
64+
65+
/**
66+
* A using alias C++ typedef type.
67+
*/
68+
class UsingAliasTypedefType extends TypedefType {
69+
70+
UsingAliasTypedefType() {
71+
usertypes(underlyingElement(this),_,14)
72+
}
73+
74+
override string getCanonicalQLClass() { result = "UsingAliasTypedefType" }
75+
76+
override string explain() { result = "using {" + this.getBaseType().explain() + "} as \"" + this.getName() + "\"" }
77+
}
78+
4879
/**
4980
* A C++ typedef type that is directly enclosed by a function.
5081
*/

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ decltypes(
675675
| 2 = class
676676
| 3 = union
677677
| 4 = enum
678-
| 5 = typedef
678+
| 5 = typedef // classic C: typedef typedef type name
679679
| 6 = template
680680
| 7 = template_parameter
681681
| 8 = template_template_parameter
@@ -684,6 +684,7 @@ decltypes(
684684
// ... 11 objc_protocol deprecated
685685
// ... 12 objc_category deprecated
686686
| 13 = scoped_enum
687+
| 14 = using_alias // a using name = type style typedef
687688
;
688689
*/
689690
usertypes(

0 commit comments

Comments
 (0)