Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum defined after a function template cannot be compiled #2525

Closed
3 tasks done
Ebola-Chan-bot opened this issue Feb 4, 2024 · 1 comment
Closed
3 tasks done

Enum defined after a function template cannot be compiled #2525

Ebola-Chan-bot opened this issue Feb 4, 2024 · 1 comment
Assignees
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@Ebola-Chan-bot
Copy link

Ebola-Chan-bot commented Feb 4, 2024

Describe the problem

C:\Users\vhtmf\AppData\Local\Temp\.arduinoIDE-unsaved202414-28316-jorhob.tu2i\sketch_feb4a\sketch_feb4a.ino:8:1: error: 'E' does not name a type
 E D()
 ^
C:\Users\vhtmf\AppData\Local\Temp\.arduinoIDE-unsaved202414-28316-jorhob.tu2i\sketch_feb4a\sketch_feb4a.ino:8:3: error: expected initializer before 'D'
 E D()
   ^

exit status 1

Compilation error: 'E' does not name a type

To reproduce

template<typename T>
void C(T F)
{}
enum E
{
  OS
}
E D()
{
  return E::OS;
}
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Expected behavior

I have verified this code in MSVC, and there should be no problem.

Arduino IDE version

版本:2.2.1 日期:2023-08-31T14:35:44.802Z CLI 版本:0.34.0 Copyright © 2024 Arduino SA

Operating system

Windows

Operating system version

版本 Windows 11 专业版 Insider Preview 版本号 23H2 安装日期 ‎2024/‎1/‎28 操作系统版本 26040.1000 体验 Windows Feature Experience Pack 1000.26040.1000.0

Additional context

No response

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@Ebola-Chan-bot Ebola-Chan-bot added the type: imperfection Perceived defect in any part of project label Feb 4, 2024
@per1234 per1234 self-assigned this Feb 4, 2024
@per1234 per1234 transferred this issue from arduino/arduino-ide Feb 4, 2024
@per1234 per1234 added topic: code Related to content of the project itself topic: build-process Related to the sketch build process labels Feb 4, 2024
@per1234
Copy link
Contributor

per1234 commented Feb 4, 2024

Hi @Silver-Fang. Thanks for taking the time to submit an issue.

I see we have another report about this at #1269.

It is best to have only a single issue per subject so we can consolidate all relevant discussion to one place, so I'll go ahead and close this in favor of the other.


As I mentioned in the other issue thread, the workaround is to manually add the function prototype at the appropriate location in the sketch, after the definition of the E type:

enum E
{
  OS
};

E D();  // Function prototype

E D()
{

I see there are also several bugs in your code that are simply a matter of it being invalid rather than anything caused by a defect or limitation in the Arduino sketch build system. So you will find the sketch still won't compile even after adding the prototype. If you would like assistance with those other problems, you are welcome to post over on Arduino Forum. I'm sure we will be able to help you over there:

https://forum.arduino.cc/c/using-arduino/programming-questions/20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants