Clang error: macro name missing (err_pp_missing_macro_name)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: macro name missing
Type Error
Category Lexical or Preprocessor Issue
Internal Id err_pp_missing_macro_name
Internal Message macro name missing
Regular Expression (?:error|fatal error)\: macro name missing
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 a #define directive that is not followed by a macro name. In the C and C++ languages, the #define directive is used to define macros, which are essentially snippets of code that are given a name. When the compiler processes a #define directive, it expects a macro name to follow the directive. If the macro name is missing, the compiler cannot proceed with the macro definition, leading to this error message. This situation typically arises from a typo or an incomplete macro definition. The error indicates that the compiler detected the #define directive but could not find a valid macro name immediately following it.  
AI Generated

Example

In the following example, a #define directive is shown without a macro name following it. This results in an error because the Clang compiler expects a macro name to be defined immediately after the #define directive. The error message generated by the compiler clearly points out the line and position in the source code where the macro name is missing. This serves as a direct indication of the problem, allowing for quick identification and correction of the issue within the code.  
AI Generated


Flags -xc

[Try out in Compiler Explorer]

Source
#define
// Missing macro name
Compiler Output
<source>:1:8: error: macro name missing


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/Lex/PPDirectives.cpp (line 324)

bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef, bool *ShadowFlag) {
  // Missing macro name?
  if (MacroNameTok.is(tok::eod))
    return Diag(MacroNameTok, diag::err_pp_missing_macro_name);

Triggered in Clang Tests

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

clang/test/Preprocessor/ifdef-recover.c

  • clang/test/Preprocessor/ifdef-recover.c:5:7: error: macro name missing
  • clang/test/Preprocessor/ifdef-recover.c:13:12: error: macro name missing
  • clang/test/Preprocessor/ifdef-recover.c:25:9: error: macro name missing