Compiler warnings

WMXZ

Well-known member
So, I get this warning (using Makefile and GCC 13.3.1 ) :
Code:
In file included from \Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/cores/teensy4/Stream.h:24,
                 from \Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/cores/teensy4/HardwareSerial.h:115,
                 from \Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/cores/teensy4/WProgram.h:47,
                 from \Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/cores/teensy4/Arduino.h:6,
                 from C:/Users/zimme/Documents/LC-MARE/microPAM/microPAM_V3.ino:31:
C:/Users/zimme/AppData/Local/Arduino15/packages/teensy/hardware/avr/0.60.2/libraries/SdFat/src/common/ArduinoFiles.h: In instantiation of 'class PrintFile<FsBaseFile>':
\Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/libraries/SdFat/src/SdFat.h:495:23:   required from here
\Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/cores/teensy4/Print.h:61:24: warning: 'virtual size_t Print::write(const uint8_t*, size_t)' was hidden [-Woverloaded-virtual=]
   61 |         virtual size_t write(const uint8_t *buffer, size_t size);
      |                        ^~~~~
In file included from \Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/libraries/SdFat/src/ExFatLib/ExFatFile.h:821,  
                 from \Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/libraries/SdFat/src/ExFatLib/ExFatVolume.h:27,
                 from \Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/libraries/SdFat/src/ExFatLib/ExFatLib.h:27,    
                 from \Users\zimme\AppData\Local\Arduino15\packages\teensy/hardware/avr/0.60.2/libraries/SdFat/src/SdFat.h:35,
                 from C:/Users/zimme/Documents/LC-MARE/microPAM/src/Storage.h:38,
                 from C:/Users/zimme/Documents/LC-MARE/microPAM/src/MTP.h:37,
                 from C:/Users/zimme/Documents/LC-MARE/microPAM/microPAM_V3.ino:68:
C:/Users/zimme/AppData/Local/Arduino15/packages/teensy/hardware/avr/0.60.2/libraries/SdFat/src/common/ArduinoFiles.h:53:10: note:   by 'PrintFile<FsBaseFile>::write'
   53 |   size_t write(uint8_t b) {
      |          ^~~~~
I do not get this warning when using TD on Arduino, so it has something to do with GCC version and default warning configurations.
The question is not how to get rid of the warning, but what it exactly means, is there potential incompatibility between Print.h and SdFat.h and how to best modify code (and then making a PR).
To answer the Question, why using GCC 13.3.1? Because I had it installed for another reason.
 
I'm not exactly sure about this, but I think when the compiler attempts to find a matching function name it will check all functions in the derived class before checking functions of a base class. Since PrintFile<FsBaseFile> is derived from Print, any attempt to use write(...) will first match the method in PrintFile and cause a compilation failure if the arguments don't match.
Another way of putting it: the compiler parses the class hierarchy performing name resolution first, then overload resolution.

The fix would be explicitly including the overloaded method(s) in the derived class, probably with a "using" statement.
 
Last edited:
OK,
the actual derived class (in common/ArduinoFiles.h) is
Code:
/**
 * \class PrintFile
 * \brief PrintFile class.
 */
template<class BaseFile>
class PrintFile : public print_t, public BaseFile {
 public:
  using BaseFile::clearWriteError;
  using BaseFile::getWriteError;
  using BaseFile::read;
  using BaseFile::write;
  /** Write a single byte.
   * \param[in] b byte to write.
   * \return one for success.
   */
  size_t write(uint8_t b) {
    return BaseFile::write(&b, 1);
  }
};
adding
Code:
  size_t write(const uint8_t *buffer, size_t size) {
    return BaseFile::write(buffer, size);
  }
to the PrintFile class solved the issue.
 
Back
Top