Clang error: a space is required between consecutive right angle brackets (use '> >') (err_two_right_angle_brackets_need_space)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: a space is required between consecutive right angle brackets (use '> >')
Type Error
Category Parse Issue
Internal Id err_two_right_angle_brackets_need_space
Internal Message a space is required between consecutive right angle brackets (use '> >')
Regular Expression (?:error|fatal error)\: a space is required between consecutive right angle brackets \(use '\> \>'\)
First Commit 2009-03-04 b1c4d5507fad The basic representation of diagnostics information in tablegen format, plus (uncommented and incomp...

Description

The error is issued by the Clang compiler when it encounters two or more consecutive right angle brackets (>) without a space between them. This situation typically arises in the context of C++ templates, where nested template declarations can lead to a sequence of right angle brackets in close succession. Prior to the adoption of the C++11 standard, which introduced the ability to parse consecutive right angle brackets in template declarations without requiring a space, the insertion of a space between each right angle bracket was necessary to avoid a parse error. The Clang compiler emits this error message to indicate the need for a space between each bracket to adhere to the syntax rules of older C++ standards that do not support this feature. The message includes a suggestion to insert a space between the consecutive right angle brackets, highlighting the corrective action needed to resolve the error.  
AI Generated

Example

In the following example, an instance of the Clang error is illustrated within the context of a C++ program that involves nested template declarations. The program attempts to declare a vector that contains vectors of integers. The critical part of the code that triggers the error is the declaration of the nested vector without a space between the consecutive right angle brackets. Such syntax was not allowed in C++ standards prior to C++11, leading to a parse error by the compiler. The purpose of showcasing this particular code snippet is to demonstrate how the absence of a space between consecutive right angle brackets causes the Clang compiler to emit an error. The error message suggests the insertion of a space between the brackets as the corrective action. The output section of the example displays the exact error message produced by the compiler, reinforcing the necessity of a space to adhere to the syntax rules required by older versions of the C++ standard.  
AI Generated


Flags -xc++ -std=c++98

[Try out in Compiler Explorer]

Source
#include <vector>

int main() {
    // Missing space between consecutive '>'
    std::vector<std::vector<int>> v;
    return 0;
}
Compiler Output
<source>:5:32: error: a space is required between consecutive right angle brackets (use '> >')


Clang Internals (17.0.6)

Git Commit Message

The basic representation of diagnostics information in tablegen format, plus (uncommented and incomplete) test conversions of the existing def files to this format.

llvm-svn: 66064

Used in Clang Sources

This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.

clang/lib/Parse/ParseTemplate.cpp (line 1203)

/// Parses a '>' at the end of a template list.
///
/// If this function encounters '>>', '>>>', '>=', or '>>=', it tries
/// to determine if these tokens were supposed to be a '>' followed by
/// '>', '>>', '>=', or '>='. It emits an appropriate diagnostic if necessary.
///
/// \param RAngleLoc the location of the consumed '>'.
///
/// \param ConsumeLastToken if true, the '>' is consumed.
///
/// \param ObjCGenericList if true, this is the '>' closing an Objective-C
/// type parameter or type argument list, rather than a C++ template parameter
/// or argument list.
///
/// \returns true, if current token does not start with '>', false otherwise.
bool Parser::ParseGreaterThanInTemplateList(SourceLocation LAngleLoc, SourceLocation &RAngleLoc, bool ConsumeLastToken, bool ObjCGenericList) {
  // ...
  // Diagnose this situation as appropriate.
  if (!ObjCGenericList) {
    // ...
    unsigned DiagId = diag::err_two_right_angle_brackets_need_space;

Triggered in Clang Tests

This section lists all internal Clang test cases that trigger the diagnostic.

clang/test/CXX/temp/temp.param/p15.cpp

  • clang/test/CXX/temp/temp.param/p15.cpp:6:8: error: a space is required between consecutive right angle brackets (use '> >')
  • clang/test/CXX/temp/temp.param/p15.cpp:8:12: error: a space is required between consecutive right angle brackets (use '> >')
  • clang/test/CXX/temp/temp.param/p15.cpp:9:5: error: a space is required between consecutive right angle brackets (use '> >')