Skip to content

[ClangFormat] Space removed in g< ::f<int>>() except for Standard: c++03 #123823

@reventlov

Description

@reventlov

In all versions of C++ supported by ClangFormat, the alternative operator spelling ("digraph") <: is treated as [. However, ClangFormat will remove a space between < and : (except when Standard: c++03 is specified, or Standard: Auto is specified and no double-closing >> is found in the source file):

g< ::T>();       // before
g<::T>();        // after, compiler error
g [ : T > ( ) ;  // C++ equivalent tokenization

This causes problems when:

  • the first template parameter must use an absolute namespace (e.g., the code is in f::g, namespace f::e exists, and the parameter is ::e::T), and
  • the code is not compiled with -fno-digraphs (or its equivalent in other compilers)

As far as I am aware, this is the only place where the "digraph" alternative spellings can change the meaning of otherwise-valid C++ code (and I believe there is no such case in C, where the digraph operators originated).

There is a (moderately annoying) workaround of adding a dummy comment:

g</**/ ::T>();  // safe

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions