Skip to content

Commit 5c727bb

Browse files
committed
[SYCL] Fix double definition of default values for template parameters.
Added SuppressDefaultTemplateArguments flag for PrintingPolicy class and use it at generation of the intergation header. Example: /// template<typename T = void> /// class A {...}; /// /*Forward declaration*/ /// template<typename T> class kernel; /// ... /// cgh.parallel_for<class kernel<A>>>( /// range<1>(1), [=](id<1> i){ /*do something*/ }); At the moment the forward declaration of class A will be generated as /// template<typename T = void> class A after this patch will be written as /// template<typename T> class A Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 9be56d5 commit 5c727bb

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

clang/include/clang/AST/PrettyPrinter.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct PrintingPolicy {
5252
MSVCFormatting(false), ConstantsAsWritten(false),
5353
SuppressImplicitBase(false), FullyQualifiedName(false),
5454
RemapFilePaths(false), PrintCanonicalTypes(false),
55-
SuppressDefinition(false) {}
55+
SuppressDefinition(false), SuppressDefaultTemplateArguments (false) {}
5656

5757
/// Adjust this printing policy for cases where it's known that we're
5858
/// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -69,6 +69,7 @@ struct PrintingPolicy {
6969
void adjustForCPlusPlusFwdDecl() {
7070
PolishForDeclaration = true;
7171
SuppressDefinition = true;
72+
SuppressDefaultTemplateArguments = true;
7273
}
7374

7475
/// The number of spaces to use to indent each line.
@@ -252,6 +253,15 @@ struct PrintingPolicy {
252253
/// \endcode
253254
unsigned SuppressDefinition : 1;
254255

256+
/// When true, suppresses printing default template arguments of a type. E.g.
257+
/// \code
258+
/// template<typename T = void> class A
259+
/// \endcode
260+
/// will be printed as
261+
/// \code
262+
/// template<typename T> class A
263+
/// \endcode
264+
unsigned SuppressDefaultTemplateArguments : 1;
255265
};
256266

257267
} // end namespace clang

clang/lib/AST/DeclPrinter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,8 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params) {
10141014

10151015
Out << *TTP;
10161016

1017-
if (TTP->hasDefaultArgument()) {
1017+
if (TTP->hasDefaultArgument()
1018+
&& !Policy.SuppressDefaultTemplateArguments ) {
10181019
Out << " = ";
10191020
Out << TTP->getDefaultArgument().getAsString(Policy);
10201021
};
@@ -1024,7 +1025,8 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params) {
10241025
Name = II->getName();
10251026
printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
10261027

1027-
if (NTTP->hasDefaultArgument()) {
1028+
if (NTTP->hasDefaultArgument()
1029+
&& !Policy.SuppressDefaultTemplateArguments ) {
10281030
Out << " = ";
10291031
NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy,
10301032
Indentation);

clang/test/CodeGenSYCL/integration_header.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct x {};
117117
template <typename T>
118118
struct point {};
119119
namespace second_namespace {
120-
template <typename T>
120+
template <typename T = int>
121121
class second_kernel;
122122
}
123123

0 commit comments

Comments
 (0)