Skip to content

Backslash incorrectly inserted into generated prototype for multiline template function  #1785

Open
@jfjlaros

Description

@jfjlaros

Describe the problem

When trying to compile the following sketch,

template <size_t N>
void test(size_t arr[N / 2]) {}

void setup() {}
void loop() {}

this error is raised:

arduino-cli compile --fqbn arduino:avr:pro --warnings all --output-dir build \
    --build-property compiler.cpp.extra_flags="-pedantic"
.../x.ino.cpp:2:7: warning: line number out of range
 #line 0 ".../x.ino"
       ^
.../x.ino:0:43: error: stray '\' in program
.../x.ino:6:7: warning: line number out of range

When the function definition is changed as follows, everything works fine.

void test(size_t arr[N >> 1]) {}

This issue seems to be independent of which core is used (tried AVR and ESP) and of which platform is used (tried Linux and Wokwi simulator).

Arduino CLI version

4a4b784

Operating system

  • Windows

Operating system version

  • Windows 11

Additional context

For reference, the following program compiles without errors or warnings

#include <cstddef>

template <size_t N>
void test(size_t arr[N / 2]) {}

int main() {
  return 0;
}

with the following command:

g++ -std=c++11 -Wall -Wextra -pedantic x.cc

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

Labels

topic: build-processRelated to the sketch build processtopic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions