Skip to content

Clang rejects braced-init-list as default non-type template parameter #49978

@PiliLatiesa

Description

@PiliLatiesa
Bugzilla Link 50634
Version 12.0
OS Linux
CC @DougGregor,@zygoloid

Extended Description

Clang rejects this code:

template<bool = {}>
int f() {}

with:

error: expected expression

However I believe that the C++ grammar permits that.

[temp.param]:

The syntax for template-parameters is:
template-parameter:
type-parameter
parameter-declaration

[dcl.fct]:

parameter-declaration:
attribute-specifier-seq_{opt} decl-specifier-seq declarator
attribute-specifier-seq_{opt} decl-specifier-seq declarator = initializer-clause
attribute-specifier-seq_{opt} decl-specifier-seq abstract-declarator_{opt}
attribute-specifier-seq_{opt} decl-specifier-seq abstract-declarator
_{opt} = initializer-clause

[dcl.init]:

initializer-clause:
assignment-expression
braced-init-list

My motivating usecase is:

template<std::true_type = {}>
int f() {}

which is accepted by G++.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"rejects-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions