Skip to content

[HardwareSerial] Fix ambiguous call of overloaded function #893

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

Merged
merged 1 commit into from
Jan 27, 2020

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Jan 27, 2020

error: call of overloaded 'HardwareSerial(int, int)' is ambiguous`

    1 | HardwareSerial Serialx(0, 1);
      |                                  ^
In file included from cores/arduino/WSerial.h:5,
                 from cores/arduino/wiring.h:47,
                 from cores/arduino/Arduino.h:32,
                 from sketch_jan27b.ino.cpp:1:
cores/arduino/HardwareSerial.h:106:5: note: candidate: 'HardwareSerial::HardwareSerial(void*, bool)'
  106 |     HardwareSerial(void *peripheral, bool halfDuplex = false);
      |     ^~~~~~~~~~~~~~
cores/arduino/HardwareSerial.h:104:5: note: candidate: 'HardwareSerial::HardwareSerial(uint32_t, uint32_t)'
  104 |     HardwareSerial(uint32_t _rx, uint32_t _tx);
      |     ^~~~~~~~~~~~~~

When the Rx Pin is 0 then the compiler doesn't know which constructor
to use as 0 can be interpreted like NULL. So both of them are valid:

 HardwareSerial(uint32_t _rx, uint32_t _tx);
 HardwareSerial(void *peripheral, bool halfDuplex = false);

Defining an explicit type avoid this issue.

Issue reported here:
https://www.stm32duino.com/viewtopic.php?f=13&t=137

```
error: call of overloaded 'HardwareSerial(int, int)' is ambiguous`

    1 | HardwareSerial Serialx(0, 1);
      |                                  ^
In file included from cores/arduino/WSerial.h:5,
                 from cores/arduino/wiring.h:47,
                 from cores/arduino/Arduino.h:32,
                 from sketch_jan27b.ino.cpp:1:
cores/arduino/HardwareSerial.h:106:5: note: candidate: 'HardwareSerial::HardwareSerial(void*, bool)'
  106 |     HardwareSerial(void *peripheral, bool halfDuplex = false);
      |     ^~~~~~~~~~~~~~
cores/arduino/HardwareSerial.h:104:5: note: candidate: 'HardwareSerial::HardwareSerial(uint32_t, uint32_t)'
  104 |     HardwareSerial(uint32_t _rx, uint32_t _tx);
      |     ^~~~~~~~~~~~~~
```

When the Rx Pin is 0 then the compiler doesn't know which constructor
to use as 0 can be interpreted like NULL. So both of them are valid:
 HardwareSerial(uint32_t _rx, uint32_t _tx);
 HardwareSerial(void *peripheral, bool halfDuplex = false);

Defining an explicit type avoid this issue.

Signed-off-by: Frederic Pillon <[email protected]>
@fpistm fpistm added the fix 🩹 Bug fix label Jan 27, 2020
@fpistm fpistm added this to the 1.9.0 milestone Jan 27, 2020
@fpistm fpistm self-assigned this Jan 27, 2020
@fpistm fpistm requested a review from ABOSTM January 27, 2020 16:45
@fpistm fpistm merged commit e013b67 into stm32duino:master Jan 27, 2020
@fpistm fpistm deleted the Fix_ambiguous branch January 27, 2020 17:04
@fpistm
Copy link
Member Author

fpistm commented Jan 27, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 🩹 Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants