Skip to content

Commit 0258ce7

Browse files
authored
Merge pull request #18362 from github/jketema/template-parameters-4
C++: Support concept templates
2 parents b18230a + 0f5b70a commit 0258ce7

File tree

11 files changed

+10227
-316
lines changed

11 files changed

+10227
-316
lines changed

cpp/downgrades/f786eb3f5dfddb0ac914ab09551bf1c5c64b47c0/old.dbscheme

Lines changed: 2377 additions & 0 deletions
Large diffs are not rendered by default.

cpp/downgrades/f786eb3f5dfddb0ac914ab09551bf1c5c64b47c0/semmlecode.cpp.dbscheme

Lines changed: 2358 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
description: Support concept templates
2+
compatibility: full
3+
concept_templates.rel: delete
4+
concept_template_argument.rel: delete
5+
concept_template_argument_value.rel: delete
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: feature
3+
---
4+
* A new class `Concept` was introduced, which represents C++20 concepts.
5+
* The `getTemplateArgumentType` and `getTemplateArgumentValue` predicates of the `Declaration` class now also yield template arguments of concepts.

cpp/ql/lib/semmle/code/cpp/Concept.qll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,32 @@ class ConceptIdExpr extends RequirementExpr, @concept_id {
159159

160160
override string getAPrimaryQlClass() { result = "ConceptIdExpr" }
161161
}
162+
163+
/**
164+
* A C++ concept.
165+
*
166+
* For example:
167+
* ```cpp
168+
* template<class T>
169+
* concept C = std::is_same<T, int>::value;
170+
* ```
171+
*/
172+
class Concept extends Declaration, @concept_template {
173+
override string getAPrimaryQlClass() { result = "Concept" }
174+
175+
override Location getLocation() { concept_templates(underlyingElement(this), _, result) }
176+
177+
override string getName() { concept_templates(underlyingElement(this), result, _) }
178+
179+
/**
180+
* Gets the constraint expression of the concept.
181+
*
182+
* For example, in
183+
* ```cpp
184+
* template<class T>
185+
* concept C = std::is_same<T, int>::value;
186+
* ```
187+
* the constraint expression is `std::is_same<T, int>::value`.
188+
*/
189+
Expr getExpr() { result.getParent() = this }
190+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ class Declaration extends Locatable, @declaration {
279279
variable_template_argument(underlyingElement(this), index, unresolveElement(result))
280280
or
281281
template_template_argument(underlyingElement(this), index, unresolveElement(result))
282+
or
283+
concept_template_argument(underlyingElement(this), index, unresolveElement(result))
282284
}
283285

284286
private Expr getTemplateArgumentValue(int index) {
@@ -289,6 +291,8 @@ class Declaration extends Locatable, @declaration {
289291
variable_template_argument_value(underlyingElement(this), index, unresolveElement(result))
290292
or
291293
template_template_argument_value(underlyingElement(this), index, unresolveElement(result))
294+
or
295+
concept_template_argument_value(underlyingElement(this), index, unresolveElement(result))
292296
}
293297
}
294298

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,24 @@ template_template_argument_value(
876876
int arg_value: @expr ref
877877
);
878878

879+
@concept = @concept_template | @concept_id;
880+
881+
concept_templates(
882+
unique int concept_id: @concept_template,
883+
string name: string ref,
884+
int location: @location_default ref
885+
);
886+
concept_template_argument(
887+
int concept_id: @concept ref,
888+
int index: int ref,
889+
int arg_type: @type ref
890+
);
891+
concept_template_argument_value(
892+
int concept_id: @concept ref,
893+
int index: int ref,
894+
int arg_value: @expr ref
895+
);
896+
879897
routinetypes(
880898
unique int id: @routinetype,
881899
int return_type: @type ref
@@ -1106,7 +1124,8 @@ frienddecls(
11061124
| @declaredtype
11071125
| @variable
11081126
| @enumconstant
1109-
| @frienddecl;
1127+
| @frienddecl
1128+
| @concept_template;
11101129

11111130
@member = @membervariable
11121131
| @function

0 commit comments

Comments
 (0)