kamocat / plog

Portable, simple and extensible C++ logging library. Ported to Arduino
Mozilla Public License 2.0
0 stars 1 forks source link

const qualifiers #1

Closed kamocat closed 4 years ago

kamocat commented 4 years ago

I have all the errors taken care of except this one:

Arduino: 1.8.12 (Linux), Board: "Adafruit Feather M0, Arduino, Off"

In file included from /home/marshal/Arduino/libraries/Plog/include/plog/Appenders/IAppender.h:2:0,
                 from /home/marshal/Arduino/libraries/Plog/include/plog/Logger.h:2,
                 from /home/marshal/Arduino/libraries/Plog/include/plog/Log.h:7,
                 from /home/marshal/Arduino/libraries/Plog/Plog.h:1,
                 from /home/marshal/Arduino/libraries/Plog/examples/hello/hello.ino:1:
/home/marshal/Arduino/libraries/Plog/include/plog/Appenders/../Record.h: In member function 'virtual const nchar* plog::Record::getMessage() const':
/home/marshal/Arduino/libraries/Plog/include/plog/Appenders/../Record.h:258:34: error: passing 'const nostringstream {aka const obufstream}' as 'this' argument discards qualifiers [-fpermissive]
             return m_message.buf();
                                  ^
In file included from /home/marshal/Arduino/libraries/SdFat/src/FatLib/ArduinoStream.h:33:0,
                 from /home/marshal/Arduino/libraries/SdFat/src/sdios.h:32,
                 from /home/marshal/Arduino/libraries/SdFat/src/SdFat.h:36,
                 from /home/marshal/Arduino/libraries/Plog/include/plog/Appenders/../Util.h:6,
                 from /home/marshal/Arduino/libraries/Plog/include/plog/Appenders/../Record.h:4,
                 from /home/marshal/Arduino/libraries/Plog/include/plog/Appenders/IAppender.h:2,
                 from /home/marshal/Arduino/libraries/Plog/include/plog/Logger.h:2,
                 from /home/marshal/Arduino/libraries/Plog/include/plog/Log.h:7,
                 from /home/marshal/Arduino/libraries/Plog/Plog.h:1,
                 from /home/marshal/Arduino/libraries/Plog/examples/hello/hello.ino:1:
/home/marshal/Arduino/libraries/SdFat/src/FatLib/bufstream.h:123:9: note:   in call to 'char* obufstream::buf()'
   char* buf() {
         ^~~
exit status 1
Error compiling for board Adafruit Feather M0.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

If I remove the const qualifier, however, the function call doesn't match because the compiler thinks that the object is going to be modified. All we're doing is getting access to the character buffer inside the obufstream, to stream it to another destination.

prototypicalpro commented 4 years ago

By removing the const qualifier on the original addMessage and then creating a const overload which calls the non-const version, I was able to fix the issue. My changes are in https://github.com/kamocat/plog/pull/2.

kamocat commented 4 years ago

Looks good, thank you.