Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamString.h:89:29: error: 'min' is not a member of 'std' #8366

Closed
6 tasks done
adams13x13 opened this issue Nov 9, 2021 · 3 comments
Closed
6 tasks done

StreamString.h:89:29: error: 'min' is not a member of 'std' #8366

adams13x13 opened this issue Nov 9, 2021 · 3 comments

Comments

@adams13x13
Copy link
Contributor

adams13x13 commented Nov 9, 2021

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12
  • Core Version: 3.0.2
  • Development Env: Arduino IDE 1.8.15
  • Operating System: Ubuntu (Linux Mint)

Settings in IDE

  • Module: "Nodemcu 1.0 (ESP-12 Module)"
  • Flash Mode: ?? [qio|dio|other]
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: ?? [ck|nodemcu]
  • Flash Frequency: ?? [40Mhz]
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200 (serial upload only)

Problem Description

When StreamString.h is included from the *.cpp file and <algorithm> is not included before, following error message is given by the compiler:

error: 'min' is not a member of 'std'

In file included from /home/testuser/git/StreamStringBugExample/Test1.cpp:4:
/home/testuser/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/StreamString.h: In member function 'virtual int S2Stream::read(uint8_t*, size_t)':
/home/testuser/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/StreamString.h:89:29: error: 'min' is not a member of 'std'
   89 |             size_t l = std::min(len, (size_t)string->length());
      |                             ^~~

The problem does not appear if StreamString.h is included from the *.ino file.

MCVE Sketch (two files)

StreamStringBugExample.ino

void do_test();

void setup() {
  do_test();
}

void loop() {
}

Test1.cpp

// #include <WString.h> // not needed as it is included from StreamString.h
#include <Stream.h> // this include is also needed for the StreamString.h
// #include <algorithm> // with this not commented out, the code would compile
#include <StreamString.h>

void do_test()
{
  StreamString s;
  s.println("This is a test");
}

Possible solution

At the beginning of StreamString.h, one should include the headers that are used by this file:

#include "Stream.h"
#include <algorithm>
@earlephilhower
Copy link
Collaborator

@adams13x13 you've found a bug and have a good fix. Would you like to make a PR implementing it, so you get credit in the git logs for fixing it?

@adams13x13
Copy link
Contributor Author

Like this? #8367

@earlephilhower
Copy link
Collaborator

Yes, great. Thx! Closing per #8367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants