Forum: Mikrocontroller und Digitale Elektronik Compiler error: enum class nach function


von Thomas F. (tobasco)


Lesenswert?

Hallo,
meine C-Skills sind etwas angestaubt 🥴 … könnte mir jemand kurz erklären 
warum dieser Code
1
void foo() { }
2
enum class Foo {bar};
3
bool bar(Foo arg) { return arg == Foo::bar; }
4
void setup() {}
5
void loop() {}
einen Compiler-Fehler wirft
1
(3:10: error: 'Foo' was not declared in this scope)

… aber keinen Fehler wirf wenn ich Zeile 1 und 2 vertausche?

: Bearbeitet durch User
von Oliver S. (oliverso)


Lesenswert?

Welcher Compiler?

Oliver
P.S. alle einigermaßen aktuellen gccs compilieren das problemlos.

https://godbolt.org/z/MnePEhWTG

C++11  (nicht C) als Sprachstandard wird natürlich benötigt

: Bearbeitet durch User
von Thomas F. (tobasco)


Lesenswert?

Oliver S. schrieb:
> Welcher Compiler?
Passiert unter Arduino IDE v.2.0.4
avr-g++ (GCC) 7.3.0

von Arduino F. (Firma: Gast) (arduinof)


Lesenswert?

Thomas F. schrieb:
> meine C-Skills
Du meinst C++, oder?

Thomas F. schrieb:
> … aber keinen Fehler wirf wenn ich Zeile 1 und 2 vertausche?
Das kann ich bestätigen!

Es wirft bei mi r folgende Meldungen:
1
sketch_mar25f:3:10: error: 'Foo' was not declared in this scope; did you mean 'foo'?
2
    3 | bool bar(Foo arg) { return arg == Foo::bar; }
3
      |          ^~~
4
      |          foo
5
sketch_mar25f:3:17: error: 'bool bar(Foo)' redeclared as different kind of entity
6
    3 | bool bar(Foo arg) { return arg == Foo::bar; }
7
      |                 ^
8
E:\Programme\arduino\portable\sketchbook\sketch_mar25f\sketch_mar25f.ino:3:6: note: previous declaration 'bool bar'
9
    3 | bool bar(Foo arg) { return arg == Foo::bar; }
10
      |      ^~~
11
cc1plus.exe: warning: unrecognized command line option '-Wno-volatile'
12
exit status 1
13
'Foo' was not declared in this scope; did you mean 'foo'?
avr-gcc-9.2.0 und C++17

von MaWin O. (mawin_original)


Lesenswert?

Thomas F. schrieb:
> meine C-Skills sind etwas angestaubt
> enum class

Das ist ja auch kein C.

von Thomas F. (tobasco)


Lesenswert?

Ich hau die Arduino IDE in die Tonne und mach mit VS-Code & PlatformIO 
weiter, da wird das ohne Fehler compiliert.

Danke für's Mitdenken
salute
Thomas

von Thomas F. (tobasco)


Lesenswert?

Wen es interresiert:
Es ist ein "bekannter" Bug der Arduino IDE, siehe hier:
https://arduino.stackexchange.com/questions/66530/

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.