[Solved] In instantiation of 'xxxx' required from here (unused parameter)

Hello,

To try to find possible flaws in my program, I activated all compilation warnings, and after solving some pending issues, these were left from the DMD2 library:

DMD2_Text.cpp: In instantiation of 'unsigned int _stringWidth(DMDFrame*, const uint8_t*, StrType) [with StrType = _FlashStringWrapper; uint8_t = unsigned char]':
DMD2_Text.cpp:182:42: required from here

DMD2_Text.cpp: In instantiation of 'unsigned int _stringWidth(DMDFrame*, const uint8_t*, StrType) [with StrType = const char*; uint8_t = unsigned char]':
DMD2_Text.cpp:237:41: required from here

DMD2_Text.cpp: In instantiation of 'unsigned int _stringWidth(DMDFrame*, const uint8_t*, StrType) [with StrType = String; uint8_t = unsigned char]':
DMD2_Text.cpp:244:38: required from here

How to resolve this notification?

P.S.: (Note: these messages only appear once, then you need to close the IDE and open the code again, to recompile the libraries)

please post the entire message

It looks like the "_FlashStringWrapper" class is only defined for AVR and ESP8266 processors. What model Arduino are you using? Maybe an ESP32?

johnwasserKarma: 2000+

It looks like the "_FlashStringWrapper" class is only defined for AVR and ESP8266 processors. What model Arduino are you using? Maybe an ESP32?

The board is Arduino Pro Mini, but I use UNO bootloader.

killzone_kidEdison

please post the entire message

Message for this code (Arduino UNO, IDE 1.8.19):

Orange color message:

/DMD2/DMD2-master/examples/Countdown/DMD2_TextBox.cpp: In member function 'virtual size_t DMD_TextBox::write(uint8_t)':
/DMD2/DMD2-master/examples/Countdown/DMD2_TextBox.cpp:55:13: warning: unused variable 'delta' [-Wunused-variable]
         int delta = cur_y + rowHeight - height; // the amount that it's over by
             ^~~~~
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In instantiation of 'unsigned int _stringWidth(DMDFrame*, const uint8_t*, StrType) [with StrType = _FlashStringWrapper; uint8_t = unsigned char]':
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:182:42:   required from here
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:139:120: warning: unused parameter 'font' [-Wunused-parameter]
 template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, const uint8_t *font, StrType str)
                                                                                                                        ^~~~
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In instantiation of 'unsigned int _stringWidth(DMDFrame*, const uint8_t*, StrType) [with StrType = const char*; uint8_t = unsigned char]':
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:237:41:   required from here
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:139:120: warning: unused parameter 'font' [-Wunused-parameter]
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In instantiation of 'unsigned int _stringWidth(DMDFrame*, const uint8_t*, StrType) [with StrType = String; uint8_t = unsigned char]':
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:244:38:   required from here
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:139:120: warning: unused parameter 'font' [-Wunused-parameter]

Full message attached.

message.txt (29.8 KB)

Hi
I see in the library... the DMD2_Text.cpp file is part of the library itself, it shouldn't be in the CountDown example folder.
Do you edited the original library example? if so, please show the edited code.

there is reference to unused param, which you omitted previously. If you turn on all warnings you will get all the warnings

Perhaps the defined constant "AVR" is not getting defined. I see that "ARDUINO_ARCH_AVR" is getting defined. Try editing the DMD2 library to replace all occurances of AVR with ARDUINO_ARCH_AVR.

Yes, actually I didn't show the other messages because I didn't understand that there was a relationship between them.

It is actually the unused variable that causes this message, but it was not possible to remove the variable without other errors occurring. It is necessary to resolve this warning in another way. I don't know if this is a BUG, because when removing the variable, another routine indicates missing the variable, so the variable is being used.

Actually only one variable is causing these messages about 'In instantiation of 'xxxx' required from here':

// Generic stringWidth implementation for various kinds of strings
template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, const uint8_t *font, StrType str)
{
  unsigned int width = 0;
  char c;
  int idx;
  for(idx = 0; c = str[idx], c != 0; idx++) {
    int cwidth = dmd->charWidth(c);
    if(cwidth > 0)
      width += cwidth + 1;
  }
  if(width) {
    width--;
  }
  return width;
}

When I make use of the 'font' variable these messages stop happening.

// Generic stringWidth implementation for various kinds of strings
template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, const uint8_t *font, StrType str)
{
  unsigned int width = 0;
  char c;
  int idx;
  c = font[0]; // <------------------------ Use of 'font' variable just to test the warning message
  for(idx = 0; c = str[idx], c != 0; idx++) {
    int cwidth = dmd->charWidth(c);
    if(cwidth > 0)
      width += cwidth + 1;
  }
  if(width) {
    width--;
  }
  return width;
}

When removing the 'font' variable from this instance, these errors below occur:

//template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, const uint8_t *font, StrType str)
template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, StrType str)
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In member function 'unsigned int DMDFrame::stringWidth_P(const char*, const uint8_t*)':
DMD2_Text.cpp:184:42: error: no matching function for call to '_stringWidth(DMDFrame*, const uint8_t*&, _FlashStringWrapper&)'
   return _stringWidth(this, font, wrapper);
                                          ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note: candidate: template<class StrType> unsigned int _stringWidth(DMDFrame*, StrType)
 template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, StrType str)
                                                                             ^~~~~~~~~~~~
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note:   template argument deduction/substitution failed:
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:184:42: note:   candidate expects 2 arguments, 3 provided
   return _stringWidth(this, font, wrapper);
                                          ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In member function 'unsigned int DMDFrame::stringWidth(const char*, const uint8_t*)':
DMD2_Text.cpp:239:41: error: no matching function for call to '_stringWidth(DMDFrame*, const uint8_t*&, const char*&)'
   return _stringWidth(this, font, bChars);
                                         ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note: candidate: template<class StrType> unsigned int _stringWidth(DMDFrame*, StrType)
 template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, StrType str)
                                                                             ^~~~~~~~~~~~
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note:   template argument deduction/substitution failed:
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:239:41: note:   candidate expects 2 arguments, 3 provided
   return _stringWidth(this, font, bChars);
                                         ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In member function 'unsigned int DMDFrame::stringWidth(const String&, const uint8_t*)':
DMD2_Text.cpp:246:38: error: no matching function for call to '_stringWidth(DMDFrame*, const uint8_t*&, const String&)'
   return _stringWidth(this, font, str);
                                      ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note: candidate: template<class StrType> unsigned int _stringWidth(DMDFrame*, StrType)
 template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, StrType str)
                                                                             ^~~~~~~~~~~~
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note:   template argument deduction/substitution failed:
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:246:38: note:   candidate expects 2 arguments, 3 provided
   return _stringWidth(this, font, str);

The other unused variable message does not interfere with the message described above.

size_t DMD_TextBox::write(uint8_t character) {
  struct FontHeader header;
  memcpy_P(&header, (void *)this->dmd.font, sizeof(FontHeader));
  uint8_t rowHeight = header.height+1;

  if(width == 0)
    width = dmd.width - left;
  if(height == 0)
    height = dmd.height - top;

  uint8_t char_width = dmd.charWidth(character) + 1;
  while((cur_x > 0 && cur_x + char_width >= this->width) || pending_newline) { // Need to wrap to new line
    if (height >= rowHeight*2) { // Can scroll
      cur_y += rowHeight;
      cur_x = 0;
      if(cur_y + rowHeight > height) { // Scroll
        // Variable 'delta' not used:
        //int delta = cur_y + rowHeight - height; // the amount that it's over by 
      }
    } else if(pending_newline) { // No room, so just clear display
      clear();
    } else { // Scroll characters horizontally
      int scroll_by = char_width - (this->width - cur_x - 1);
      scrollX(-scroll_by);
    }
    pending_newline = false;
  }

  if(character == '\n') {
    pending_newline = true;
    // clear the rest of the line after the current cursor position,
    // this allows you to then use reset() and do a flicker-free redraw
    dmd.drawFilledBox(cur_x+left,cur_y+top,left+width,cur_y+top+rowHeight, inverted ? GRAPHICS_ON : GRAPHICS_OFF);
  }

  dmd.drawChar(cur_x+left,cur_y+top,character, inverted ? GRAPHICS_OFF : GRAPHICS_ON);
  cur_x += char_width;
  return 1;
}

If you remove just ‘font’ it should work


const uint8_t *

Thanks for your input, the message is related to a variable not used in the declaration, but which is used in a later implementation (a BUG perhaps?).

It didn't work, it didn't compile, and it generated error messages:

DMD2_Text.cpp:140:105: error: expected identifier before ',' token
 template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, , const uint8_t *, StrType str)
                                                                                                         ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In member function 'unsigned int DMDFrame::stringWidth_P(const char*, const uint8_t*)':
DMD2_Text.cpp:184:42: error: no matching function for call to '_stringWidth(DMDFrame*, const uint8_t*&, _FlashStringWrapper&)'
   return _stringWidth(this, font, wrapper);
                                          ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note: candidate: template<class StrType> unsigned int _stringWidth(DMDFrame*, int, const uint8_t*, StrType)
 template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, , const uint8_t *, StrType str)
                                                                             ^~~~~~~~~~~~
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note:   template argument deduction/substitution failed:
/arduino-1.8.19/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/arduino-1.8.19/hardware/arduino/avr/cores/arduino -I/arduino-1.8.19/hardware/arduino/avr/variants/standard -I/arduino-1.8.19/hardware/arduino/avr/libraries/SPI/src /tmp/arduino_build_99606/sketch/DMD2_Timer.cpp -o /tmp/arduino_build_99606/sketch/DMD2_Timer.cpp.o
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:184:42: note:   candidate expects 4 arguments, 3 provided
   return _stringWidth(this, font, wrapper);
                                          ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In member function 'unsigned int DMDFrame::stringWidth(const char*, const uint8_t*)':
DMD2_Text.cpp:239:41: error: no matching function for call to '_stringWidth(DMDFrame*, const uint8_t*&, const char*&)'
   return _stringWidth(this, font, bChars);
                                         ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note: candidate: template<class StrType> unsigned int _stringWidth(DMDFrame*, int, const uint8_t*, StrType)
 template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, , const uint8_t *, StrType str)
                                                                             ^~~~~~~~~~~~
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note:   template argument deduction/substitution failed:
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:239:41: note:   candidate expects 4 arguments, 3 provided
   return _stringWidth(this, font, bChars);
                                         ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp: In member function 'unsigned int DMDFrame::stringWidth(const String&, const uint8_t*)':
DMD2_Text.cpp:246:38: error: no matching function for call to '_stringWidth(DMDFrame*, const uint8_t*&, const String&)'
   return _stringWidth(this, font, str);
                                      ^
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note: candidate: template<class StrType> unsigned int _stringWidth(DMDFrame*, int, const uint8_t*, StrType)
 template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, , const uint8_t *, StrType str)
                                                                             ^~~~~~~~~~~~
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:140:77: note:   template argument deduction/substitution failed:
/DMD2/DMD2-master/examples/Countdown/DMD2_Text.cpp:246:38: note:   candidate expects 4 arguments, 3 provided
   return _stringWidth(this, font, str);

obviously, where that extra comma came from?

Oh my! :man_facepalming:

template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, , const uint8_t *, StrType str)

Now it really worked, the messages no longer appear. But where can I find the explanation for this solution?

//template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, const uint8_t *font, StrType str)
template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, const uint8_t *, StrType str)

there are many ways to suppress unused var warning, first result on google for example c++ - How do I best silence a warning about unused variables? - Stack Overflow

1 Like

(does nothing) so that a compiler sees it is used

Oh boy! :rofl:

It really works! :sweat_smile:

template <class StrType> __attribute__((always_inline)) inline unsigned int _stringWidth(DMDFrame *dmd, const uint8_t *font, StrType str)
{
  (void)font; // <---- (does nothing) so that a compiler sees it is used (hehehehe)

When a variable is a param in function, it gets assigned a value when function is called. If you remove the variable, nothing is assigned so it cannot be unused, so compiler doesn’t complain.

I suppose casting it, to void or other type, is technically using the variable, which also removes warning

If I wanted to make a point that variable is unused, I’d go with explicit option using ‘unused’ attribute

I wish I could explain the lack of response, I understand the frustration with warning messages, and I appreciate suggestions, I've had some severe health issues the last 5-7 years, I've submitted your suggestions as emailed to the github.

I'm going to still be very intermittent, but yeah, I guess everybody can try it out and see if the annoying messages go away.

Sorry.

I'm not as active with programming and development in general, I still love it but I've been too unwell to do anything, at least this fixes some annoying issues with the library

Thanks for the suggestion, this library not really "mine", I'm just meant to be a maintainer, getting myself together with health issues and making steady progress, I'd like to get into this all again at some point, I even had boards made for this library and still have the hardware floating around to do the esp8266 stuff. although the 32... that might be something worth looking at...

might be time for me to fire up EAGLE and see what the 32 can do... not sure when, but feeling like it's a good idea, one core for wifi/network, one core for display, sounds good...

1 Like

Hi, don't worry, you don't need to apologize for anything.

I just left the information there in the repository, so that other people can know that it is something already known.

But thank you for your effort to take the time to leave a feedback here.

Thank you, take care.