mobizt / Firebase-ESP-Client

[DEPRECATED]šŸ”„Firebase Arduino Client Library for ESP8266, ESP32 and RP2040 Pico. The complete, fast, secured and reliable Firebase Arduino client library that supports RTDB, Cloud Firestore, Firebase and Google Cloud Storage, Cloud Messaging and Cloud Functions for Firebase.
MIT License
471 stars 101 forks source link

Intellisense Errors with Strings #459

Closed djmick closed 1 year ago

djmick commented 1 year ago

I'm using Visual Studio 2022 with Visual Micro which is an Arduino IDE for Visual Studio (not to be confused with VS Code). i'm getting dozens of errors when trying to combine Strings together using +. For example String "s3 = s1 + s2". The error message i'm receiving is "more than one operator "+" matches these operands". This issue only occurs when i add the Firebase-ESP-Client to my project. Based on the error message below, it looks like it has to do with MB_String.

_Severity Code Description Project File Line Suppression State Detail Description Error (active) E0350 more than one operator "+" matches these operands: MyProject_ESP32_S2_Firebase C:\Users\XXXX\Documents\Arduino\MyProject_ESP32_S2_Firebase\Firebase.ino 530 function "operator+(MB_String &&lhs, const MB_String &rhs)" (declared at line 2044 of "C:\Users\XXXX\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src\json\MBString.h") function "operator+(const StringSumHelper &lhs, const String &rhs)" (declared at line 186 of "C:\Users\XXXX\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.6\cores\esp32\WString.h") operand types are: const char [2] + String

Notice the yellow highlights in the screen shot below. Also "fbDbPath" is a global string variable image

I've tried both a Adafruit ESP32 & Adafruit ESP32-S2

IDE and its version:

ESP8266 Arduino Core SDK version

mobizt commented 1 year ago

This is not code or library error.

It's not error specific to this library.

It's IDE error related to compiler as you can test with just simple Arduino String concatenation like this.

String a = "something" + String(" is wrong");

The above line causes the IDE intelligence error in Visual Studio IDE too.

This intellisense error also existed in VSCode + PlatformIO plugin too.

You can ignore this error in your IDE.

mobizt commented 1 year ago

You can test with this simple sketch

void setup()
{
  Serial.begin(115200);
  Serial.println("something" + String(" is wrong"));
}

void loop()
{
}
mobizt commented 1 year ago

This intellisense issue also discussed here (in VSCode not Visual Studio).

AndhikaWB commented 1 year ago

It can be fixed by using typedef alias, but just use the alias for + operation only, other normal string should still be written as String.

#include <WString.h>
typedef StringSumHelper str;

#define SSID "abcd"
#define KEY "1234"

void setup()
{
  Serial.begin(115200);

  Serial.println("SSID:" + (str) SSID);
  Serial.println("Password:" + (str) KEY);
}

void loop()
{
}