Skip to content

token pasting and empty tokens #259

Open

Description

@matlo
// test.h

#define SIMPLE(T, NAME) \
   T NAME;

#define ADVANCED(T, PREFIX, NAME, EXTENSION) \
   SIMPLE(T, PREFIX##NAME##EXTENSION)

ADVANCED(int, , foo, )
cppcheck -E test.h
Checking test.h ...
[test.h:6]: (error) failed to expand 'ADVANCED', Invalid ## usage when expanding 'ADVANCED'.
cpp test.h 
# 1 "test.h"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "test.h"
# 9 "test.h"
int foo;

Activity

  1. matlo commented on Apr 12, 2022

    @matlo
    Author

    Same result with 0fe0ab6:

    ./simplecpp test.h
    
    test.h:6: syntax error: failed to expand 'ADVANCED', Invalid ## usage when expanding 'ADVANCED': Unexpected token ',foo'
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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