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

Compilation fails due to function reordering #500

Open
Labels
@Floessie

Description

@Floessie

Describe the problem

In order to make it easier for beginners to get started with writing Arduino sketches, and for the convenience of all users, Arduino CLIautomatically generates and adds prototypes for functions defined in a.ino file of a sketch.

If the user has already manually added function prototypes to the sketch, generation is skipped for those functions.

🐛 When the following sketch code is compiled, Arduino CLI generates prototypes even though they are already present and injects them at inappropriate locations:

namespace{structState {    };structConfiguration {enumclassAutoMode :uint8_t {            INDEPENDENT,            LINKED        };    };structStatsMinMax {    };structStatsDurations {    };enumclassCommand :uint8_t {        GET_STATE,        GET_CONFIG,        GET_STATS_MIN_MAX,        GET_STATS_DURATIONS    };voiddump(const StatsMinMax& stats_min_max,const StatsDurations& stats_durations)    {    }template<typename T>    CommandgetCommand(const T& type);template<>    CommandgetCommand(const State& type)    {return Command::GET_STATE;    }template<>    CommandgetCommand(const Configuration& type)    {return Command::GET_CONFIG;    }template<>    CommandgetCommand(const StatsMinMax& type)    {return Command::GET_STATS_MIN_MAX;    }template<>    CommandgetCommand(const StatsDurations& type)    {return Command::GET_STATS_DURATIONS;    }}voidsetup(){}voidloop(){}

The output is:

sketch_nov27a:33:49: error: 'getCommand' is not a template function                                                  ^sketch_nov27a:39:57: error: 'getCommand' is not a template function                                                          ^sketch_nov27a:45:55: error: 'getCommand' is not a template function                                                        ^sketch_nov27a:51:58: error: 'getCommand' is not a template function                                                           ^exit status 1'getCommand' is not a template function

Seems like the template function prototype isn't picked up. Removingdump() makes it compile again as does removing theenum class insideConfiguration. A real workaround is to define the prototype like so:

template<typename T>CommandgetCommand(const T& type){}

To reproduce

Compile the sketch I provided above for any board.

Expected behavior

Function prototypes are not generated when they are already present in the sketch code.

Arduino CLI version

Original report

Arduino IDE 1.8.10

Last verified with

20c9dd4

Additional context

The code compiles successfully when using Arduino IDE 1.8.5.


As template function prototype declaration is normally (speaking for C++) sufficient it would be nice if the Arduino toolchain could cope with it.

Related

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp