Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cannot compile a function template after a struct definition #2977

Open
Labels
topic: build-processRelated to the sketch build processtopic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project
@Ebola-Chan-bot

Description

@Ebola-Chan-bot

Describe the problem

Unable to compile a function template after a struct definition. The code passed compilation with multiple different versions of the compilers onCompiler Explorer, but fails in Arduino IDE.

To reproduce

Setup environment

$ arduino-cli versionarduino-cli  Version: git-snapshot Commit: eb4e2ca77 Date: 2025-08-14T05:11:39Z$ mkdir "/tmp/FooSketch"$ echo 'struct foo_t{};template<typename T>void bar(foo_t Parameter) {}void setup() {}void loop() {}' > "/tmp/FooSketch/FooSketch.ino"

Demo

$ arduino-cli compile --fqbn arduino:avr:uno "/tmp/FooSketch"C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:2:30: error: variable or field 'bar' declared void struct foo_t{};                              ^C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:2:30: error: 'foo_t' was not declared in this scopeC:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:2:30: note: suggested alternative: 'fpos_t' struct foo_t{};                              ^                              fpos_tUsed platform Version Patharduino:avr   1.8.6   C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6Error during build: exit status 1

🐛 There was a spurious compilation failure of valid code.

By looking at the C++ code generated by the Arduino sketch preprocessor, we can see the cause of the error:

$ arduino-cli compile --fqbn arduino:avr:uno --preprocess "/tmp/FooSketch"#include <Arduino.h>#line 1 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"#line 2 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"template<typename T>void bar(foo_t Parameter);#line 5 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"void setup();#line 6 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"void loop();#line 2 "C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino"struct foo_t{};template<typename T>void bar(foo_t Parameter) {}void setup() {}void loop() {}

🐛 The spurious compilation failure was caused by Arduino CLI placing the prototype for thebar function before the declaration of thefoo_t type.

Expected behavior

Successful compilation

Arduino CLI version

eb4e2ca

Operating system

Windows

Operating system version

11

Additional context

Related

Workaround

Manually add a function prototype at the appropriate location:

structStruct{};template<typename T>voidFunction(Struct Parameter);// Manually added function prototype to work around prototype generator bug.template<typename T>voidFunction(Struct Parameter) {}voidsetup() {}voidloop() {}

Issue checklist

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

Metadata

Metadata

Assignees

No one assigned

    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


      [8]ページ先頭

      ©2009-2025 Movatter.jp