a function-definition is not allowed here / expected '}' at end of input

  • Arduino C++
  • ESP32
  • ESP8266

You may see

error: a function-definition is not allowed here before '{' token
error: expected '}' at end of input
error: expected declaration before '}' token

Why it happens

  • A } is missing after an if, for or function, or there's one too many.

How to fix it

  1. Press Ctrl+T in the Arduino IDE to line the code up. The place where the indent looks wrong is where the bracket is missing.
  2. Click next to a {: the IDE marks its partner.
  3. Add the missing }, or delete the extra one.

It worked if: After Ctrl+T, void setup() and void loop() both start at the left edge.

Seen in a real run (some lines are close variants of it). Produced with Arduino CLI 1.5.1 and Arduino AVR core 1.8.8 (the same compiler the Arduino IDE uses).

Didn't help? Search another error or ask us.