Error: macro "max" requires 2 arguments, but only 1 given 397 | max() noexcept

Hi,
Device: ESP8266 ESP-12F NodeMCU
OS: Mac M1 Ventura 13.2
Arduino IDE 2.2.1

I am trying to verify this sketch, but I get strange errors. All libraries (WifiManager 0.15.0 nad MySensors 2.3.2) are included. Some guys from the project already encountered with same errors and they solved it by downgrading Arduino IDE. I don't think that downgrade should be the right solution. Could you please provide some guidance why I get these errors what others don't?

Thank you,

Sketch:

Errors:

In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:397:6: error: macro "max" requires 2 arguments, but only 1 given
  397 |  max() noexcept
      |      ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:98: note: macro "max" defined here
   98 | #define max(a,b) ((a)>(b)?(a):(b)) //!< max
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:398:37: error: macro "max" requires 2 arguments, but only 1 given
  398 |  { return numeric_limits<_Rep>::max(); }
      |                                     ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:98: note: macro "max" defined here
   98 | #define max(a,b) ((a)>(b)?(a):(b)) //!< max
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:401:6: error: macro "min" requires 2 arguments, but only 1 given
  401 |  min() noexcept
      |      ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:94: note: macro "min" defined here
   94 | #define min(a,b) ((a)<(b)?(a):(b)) //!< min
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:576:6: error: macro "min" requires 2 arguments, but only 1 given
  576 |  min() noexcept
      |      ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:94: note: macro "min" defined here
   94 | #define min(a,b) ((a)<(b)?(a):(b)) //!< min
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:577:46: error: macro "min" requires 2 arguments, but only 1 given
  577 |  { return duration(duration_values<rep>::min()); }
      |                                              ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:94: note: macro "min" defined here
   94 | #define min(a,b) ((a)<(b)?(a):(b)) //!< min
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:580:6: error: macro "max" requires 2 arguments, but only 1 given
  580 |  max() noexcept
      |      ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:98: note: macro "max" defined here
   98 | #define max(a,b) ((a)>(b)?(a):(b)) //!< max
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:581:46: error: macro "max" requires 2 arguments, but only 1 given
  581 |  { return duration(duration_values<rep>::max()); }
      |                                              ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:98: note: macro "max" defined here
   98 | #define max(a,b) ((a)>(b)?(a):(b)) //!< max
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:858:6: error: macro "min" requires 2 arguments, but only 1 given
  858 |  min() noexcept
      |      ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:94: note: macro "min" defined here
   94 | #define min(a,b) ((a)<(b)?(a):(b)) //!< min
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:859:36: error: macro "min" requires 2 arguments, but only 1 given
  859 |  { return time_point(duration::min()); }
      |                                    ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:94: note: macro "min" defined here
   94 | #define min(a,b) ((a)<(b)?(a):(b)) //!< min
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:862:6: error: macro "max" requires 2 arguments, but only 1 given
  862 |  max() noexcept
      |      ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:98: note: macro "max" defined here
   98 | #define max(a,b) ((a)>(b)?(a):(b)) //!< max
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:863:36: error: macro "max" requires 2 arguments, but only 1 given
  863 |  { return time_point(duration::max()); }
      |                                    ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:98: note: macro "max" defined here
   98 | #define max(a,b) ((a)>(b)?(a):(b)) //!< max
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:1045:49: error: macro "min" requires 2 arguments, but only 1 given
 1045 |       static_assert(system_clock::duration::min()
      |                                                 ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:94: note: macro "min" defined here
   94 | #define min(a,b) ((a)<(b)?(a):(b)) //!< min
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:1191:37: error: macro "min" requires 2 arguments, but only 1 given
 1191 |     operator""min(long double __mins)
      |                                     ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:94: note: macro "min" defined here
   94 | #define min(a,b) ((a)<(b)?(a):(b)) //!< min
      | 
In file included from /Users/attila/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/Ticker/src/Ticker.h:24,
                 from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:137:
/Users/attila/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/xtensa-lx106-elf/include/c++/10.3.0/chrono:1197:21: error: macro "min" requires 2 arguments, but only 1 given
 1197 |       operator""min()
      |                     ^
In file included from /Users/attila/Documents/Arduino/mqtt_wifi_gateway/mqtt_wifi_gateway.ino:134:
/Users/attila/Documents/Arduino/libraries/MySensors/MySensors.h:94: note: macro "min" defined here
   94 | #define min(a,b) ((a)<(b)?(a):(b)) //!< min
      | 

exit status 1

Compilation error: exit status 1

What happens when you put the following lines at the top of your sketch?

#undef max
#undef min

No, unfortunately I still get same errors. :frowning:

Please post the actual sketch where these errors occur - what you posted doesn't seem to contain those lines.

Have you tried to define a function called max() ? A preprocessor macro called max would "overwrite" that...

Ok, so let's see the first error as an example. There is chain of inclusions. My sketch includes
#include <Ticker.h> and that one includes #include <chrono> what generates the error as I can see.
This chrono is a thousands lines long file part of the C++ library as I can see. I post here the description of the file and lines which throw the error.

// <chrono> -*- C++ -*-

// Copyright (C) 2008-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file include/chrono
 *  This is a Standard C++ Library header.
 *  @ingroup chrono
 */

#ifndef _GLIBCXX_CHRONO
#define _GLIBCXX_CHRONO 1

#pragma GCC system_header

#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else

...

//from line 570
// 20.11.5.4 special values
	static constexpr duration
	zero() noexcept
	{ return duration(duration_values<rep>::zero()); }

	static constexpr duration
	min() noexcept
	{ return duration(duration_values<rep>::min()); }

	static constexpr duration
	max() noexcept
	{ return duration(duration_values<rep>::max()); }

      private:
	rep __r;
      };

    /// @relates duration @{
...

Your original post shows that you have a macro max being defined:

Therefore, the preprocessor will see the max here:

and try to use it to expand the defined max macro.

So that code relies on there being no max macro defined at that point.

But, as the error says, the max macro requires two parameters - hence you get the error.

Probably not so much the IDE itself, but one of its default libraries has "broken"

What do you think what can I do to resolve it? I am not a developer so I am not able to fix these libraries. :confused:

sounds like downgrading the IDE is your best bet :man_shrugging:

I removed Aruduino IDE 2.2.1, and deleted folders which contained "wrong" files and installed Arduino IDE 1.8.19, but I still get the same errors. No idea what to do. :sob:

The library tests whether `max` and `min` are defined and if not, it uses macros:

You could try to make sure that max and min are defined before MySensors.h is included.

I am not sure where max is defined, but my first guesses would be:

#include <math.h>

or:

#include <bits/stl_algobase.h>

The messages in the OP tell you:

I was referring to the (probably template) function max, not the macro.

Now we can see why the compiler gets confused!

:rofl: :joy: :sweat_smile:

Yes, macros should be avoided like the plague.

[edit]

On second thought, the suggestion above will not work. defined() only checks whether a macro of that name exists.

[edit2]

You could try to add the following lines before including MySensors.h.

#define max max
#define min min

Since I cannot reproduce the error, I tested this approach as follows.

void test(int const a) {
  Serial.print("function ");
  Serial.println(a);
}

#define test test  // Comment out this line to change the behaviour of `test`.

#if !defined(test)
#  define test(a) Serial.print("macro "); Serial.println(a)
#endif


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

  test(1);  // Prints "function 1" when `test` is defined as a macro, "macro 1" otherwise.
}

void loop() {}

The error throws in chrono AFTER the defines were made in MySensors.h.

Best way to solve it IMO would be to locate your MySenors.h file and add

#undef max
#undef min

to the end of the file.

On a second thought, the defines will most likely be used outside the header file. In that case I would just rename the definitions in MySensors.h properly:

In MySensors.h change:

#define max(a,b) ((a)>(b)?(a):(b)) //!< max
#define min(a,b) ((a)<(b)?(a):(b)) //!< min

to

#define __MYSENSOR_MAX(a,b) ((a)>(b)?(a):(b)) //!< max
#define __MYSENSOR_MIN(a,b) ((a)<(b)?(a):(b)) //!< min

The preprocessor will the tell you where those defines where actually used by throwing errors for undefined function min/max. Post the error log here and we will see how bad it is to rename those occurrences.

There are checks for previously defined macros (see post #10), so defining them as no-ops should work.

I don't have the files but if that is the case your solution is the clearly best.

[edit 1]

  • I didn't look at the files.

To clarify:

Change your local file PiHome_WiFi_Gateway_ESP8266.ino at line 133 from:

const char* host = "pihomegw";
#include <MySensors.h>

//for LED status
#include <Ticker.h>

to

const char* host = "pihomegw";

//// FIX
#define max max
#define min min

#include <MySensors.h>

//for LED status
#include <Ticker.h>

Hi guys,
Thank you for all your efforts, I really appreciate that. Your suggestions worked more or less. Those hid min max macro related errors but then additional errors came up. After trying different versions of libraries I found this post where it was clearly stated that the officially supported version by MySensors of ESP8266 framework is only v2.6.2.
Since I downgraded I can comply any sketch without issues even with Arduino IDE v2.
It was a nightmare. :smiley:
Thank you.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.