Skip to content

Incorrect expansion of ,##__VA_ARGS__ in macro #4639

Closed
@wmacevoy

Description

@wmacevoy

Basic Infos

  • [ X] This issue complies with the issue POLICY doc.
  • [X ] I have read the documentation at readthedocs and the issue is not addressed there.
  • [ ?] I have tested that the issue is present in current master branch (aka latest git).
    Latest build from README docs build failed (Mac OS 10.12.6) on python get.py with:
    > cd esp8266/tools
    > python get.py
    IOError: [Errno socket error] [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)
  • [ X] I have searched the issue tracker for a similar issue.
  • [ X] If there is a stack dump, I have decoded it.
  • [X ] I have filled out all fields below.

Platform

  • Hardware: Generic ESP8266 device
  • Core Version: 2.4.1 - could not build from git
  • Development Env: Arduino IDE 1.8.5
  • Operating System: MacOS

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: qio
  • Flash Size: 512MB
  • lwip Variant: v2mss536
  • Reset Method: ck
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: na compile time error
  • Upload Speed: na compile time error

Problem Description

g++ supports variadic macros which cleanly reduces to 0 arguments with the notation

#define va_macro(...) va(begin, ##__VA_ARGS__, end)

The ,##__VA_ARGS__ notation expands to nothing if no arguments are given (the leading comma is removed), while the comma remains for 1 or more arguments.

This works correctly on uno, mega and esp32 boards, but fails to expand correctly on esp8266. This notation is important for variable parameter macros. Here is a sketch that compiles under uno, mega, esp32, but has a compile-time-error for esp8266, with log files for uno, mega, esp32 (correct) and esp8266 (compile time error):

https://github.com/mmurdoch/arduinounit/tree/pr65/va_args

#define va_macro(...) va_sub(-9,##__VA_ARGS__,9)

// Unimportant, just to have something the va_macro can compile to
void va_sub(int first, int last) { }
void va_sub(int first, int va1, int last) { }
void va_sub(int first, int va1, int va2, int last) {}

void setup() {
   va_macro(1,2);  // ok: expands to va_sub(-9,1,2,9);
   va_macro(1); // ok: expands to va_sub(-9,1,9); 
   va_macro(); // fail: expands to va_sub(-9,,9) on ESP 8266, but should be va_sub(-9,9);
}

void loop() {

}

Debug Messages

None.  Does not compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions