esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
16.07k stars 13.33k forks source link

Pollution of global namespace due to using namespace EspSoftwareSerial; #9055

Open RobertGnz opened 11 months ago

RobertGnz commented 11 months ago

In version 3.1.1 of SoftwareSerial.h we have:

enum SoftwareSerialConfig { SWSERIAL_5N1 = SWSERIAL_PARITY_NONE, etc...

this was changed in version 3.1.2 with:

enum Config { SWSERIAL_5N1 = SWSERIAL_PARITY_NONE, etc...

which lead to a conflicting name problem when Config is used in an application program but with another definition despite the namespace statement added in SoftwareSerial.h version 3.1.2

mcspr commented 11 months ago

Also see https://github.com/plerup/espsoftwareserial/issues/301

edit: nvm the code snippet, enum does not work like that (sadly)

RobertGnz commented 11 months ago

Can't use 3.1.2 release because it should oblige to change all existing applications.

RobertGnz commented 11 months ago

Also see plerup/espsoftwareserial#301

edit: nvm the code snippet, enum does not work like that (sadly)

The problem comes from the directive: " using namespace EspSoftwareSerial; " line 433 which is not a good pratice in terms of programming because it may lead to collision problem.

Please have a look at this page https://learn.microsoft.com/en-us/cpp/cpp/namespaces-cpp?view=msvc-170 and pay a special attention to the note in chapter "Using directives"

mcspr commented 11 months ago

What I mean, the fix should happen upstream first. Please re-read the issue I linked, swserial is an external lib :>

RobertGnz commented 11 months ago

What I mean, the fix should happen upstream first. Please re-read the issue I linked, swserial is an external lib :>

You just linked back to this issue and nothing else.

Pablo2048 commented 11 months ago

EspSoftwareSerial is external library, so @mcspr tries to say that you are barking on wrong tree here - please report the error in the original one, because the original repository has to be changed first (it's used as submodule).

RobertGnz commented 11 months ago

EspSoftwareSerial is external library, so @mcspr tries to say that you are barking on wrong tree here - please report the error in the original one, because the original repository has to be changed first (it's used as submodule).

Where is the original repository ?

Pablo2048 commented 11 months ago

Did you try to click https://github.com/esp8266/Arduino/tree/master/libraries at the library? It leads to https://github.com/plerup/espsoftwareserial/tree/bcfd6d10e6a45a0d07705d08728f293defe9cc1d ...

RobertGnz commented 10 months ago

Did you try to click https://github.com/esp8266/Arduino/tree/master/libraries at the library? It leads to https://github.com/plerup/espsoftwareserial/tree/bcfd6d10e6a45a0d07705d08728f293defe9cc1d ...

The problem comes because of the directive using namespace EspSoftwareSerial wich leads to a global pollution.

Pablo2048 commented 10 months ago

Yes, exactly described here https://github.com/plerup/espsoftwareserial/issues/301 as @mcspr told you... This is wrong repository as it has nothing to do with the issue.