arduino / arduino/ArduinoCore-avr

Remove `-fpermissive` flag from compilation patterns

Open
#268 8 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Today, I ran into some problem, which turned out to be caused by the compiler happily passing an `int` to a function that expected a pointer. Closer investigation showed that a warning was issued, where I would have expected an error. This seems to because of the `-fpermissive` flag, which gets passed by the avr core by default. According to the gcc manpage:

```
-fpermissive
Downgrade some diagnostics about nonconformant code from
errors to warnings. Thus, using -fpermissive allows some
nonconforming code to compile.
```

I'm not sure what changes this makes exactly and if we need it at all. If the other changes are similar to this one, I think it should be disabled at some point (but it will probably break existing code that isn't quite correct, but now happens to work)...

For reference, here's a simplified version of my problem:

```cpp
void func(Foo *ptr);

int main() {
func(1);
return 0;
}
```

(the real problem was more subtle, involving a struct with a conversion operator to int, which got silently converted to a pointer containing rubbish when I forgot the `&` operator when trying to pass the struct's address to a function).

### Additional context

#### Additional requests

- https://github.com/arduino/ArduinoCore-avr/issues/268#issuecomment-248200635
- https://github.com/arduino/ArduinoCore-avr/issues/268#issuecomment-254016077
- https://github.com/arduino/ArduinoCore-avr/issues/268#issuecomment-256914284
- https://github.com/arduino/Arduino/issues/10154
- https://github.com/arduino/Arduino/issues/10154#issuecomment-643845516
- https://github.com/arduino/Arduino/issues/11402
- https://github.com/arduino/Arduino/issues/11639
- https://forum.arduino.cc/t/weird-warning-why/1420379

#### Related

- https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/13

---

Keywords

- "permissive"

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the avr core's compilation patterns that add `-fpermissive`, then reproduce the simplified invalid pointer-call example with and without the flag. Review the linked Arduino issues for compatibility concerns; done means the flag is removed where appropriate and the affected compilation checks or builds still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, compilers
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.