Bug 966257

Summary: snapper fails to build with GCC 6
Product: [openSUSE] openSUSE Tumbleweed Reporter: Richard Biener <rguenther>
Component: BasesystemAssignee: David Sterba <dsterba>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: aschnell, dsterba, fvogt
Version: Current   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Richard Biener 2016-02-11 14:28:01 UTC
In openSUSE:Factory:Staging:Gcc6 snapper fails to build with

[  127s] /bin/sh ../libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I..  -I/usr/include/libxml2 -DCONFDIR='"/etc/sysconfig"' -D_FILE_OFFSET_BITS=64 -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -Wno-error=misleading-indentation -Wno-error=narrowing -Wno-error=nonnull -Wno-error=unused-const-variable -g -DNDEBUG -std=c++0x -Wall -Wextra -Wformat=2 -Wnon-virtual-dtor -Wno-unused-parameter -MT BtrfsUtils.lo -MD -MP -MF .deps/BtrfsUtils.Tpo -c -o BtrfsUtils.lo BtrfsUtils.cc
[  127s] libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -I/usr/include/libxml2 -DCONFDIR=\"/etc/sysconfig\" -D_FILE_OFFSET_BITS=64 -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -Wno-error=misleading-indentation -Wno-error=narrowing -Wno-error=nonnull -Wno-error=unused-const-variable -g -DNDEBUG -std=c++0x -Wall -Wextra -Wformat=2 -Wnon-virtual-dtor -Wno-unused-parameter -MT BtrfsUtils.lo -MD -MP -MF .deps/BtrfsUtils.Tpo -c BtrfsUtils.cc  -fPIC -DPIC -o .libs/BtrfsUtils.o
[  127s] In file included from /usr/include/c++/6/bits/char_traits.h:39:0,
[  127s]                  from /usr/include/c++/6/ios:40,
[  127s]                  from /usr/include/c++/6/istream:38,
[  127s]                  from /usr/include/c++/6/sstream:38,
[  127s]                  from ../snapper/Log.h:26,
[  127s]                  from BtrfsUtils.cc:38:
[  127s] /usr/include/c++/6/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
[  127s]      min(const _Tp&amp; __a, const _Tp&amp; __b, _Compare __comp)
[  127s]                                                         ^
[  127s] /usr/include/c++/6/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2
[  127s]      max(const _Tp&amp; __a, const _Tp&amp; __b, _Compare __comp)
[  127s]                                                         ^
[  127s] In file included from /usr/include/c++/6/chrono:40:0,
[  127s]                  from ../snapper/AppUtil.h:37,
[  127s]                  from BtrfsUtils.cc:39:
[  127s] /usr/include/c++/6/limits:320:11: error: macro "min" requires 2 arguments, but only 1 given
[  127s]        min() _GLIBCXX_USE_NOEXCEPT { return _Tp(); }
[  127s]            ^
[  127s] /usr/include/c++/6/limits:324:11: error: macro "max" requires 2 arguments, but only 1 given
[  127s]        max() _GLIBCXX_USE_NOEXCEPT { return _Tp(); }
[  127s]            ^
[  127s] /usr/include/c++/6/limits:387:11: error: macro "min" requires 2 arguments, but only 1 given
[  127s]        min() _GLIBCXX_USE_NOEXCEPT { return false; }
[  127s]            ^
[  127s] /usr/include/c++/6/limits:390:11: error: macro "max" requires 2 arguments, but only 1 given
[  127s]        max() _GLIBCXX_USE_NOEXCEPT { return true; }
[  127s]            ^
[  127s] /usr/include/c++/6/limits:394:38: error: macro "min" requires 2 arguments, but only 1 given
[  127s]        lowest() noexcept { return min(); }
[  127s]                                       ^

...


I supect either it doesn't cope with the now default -std=gnu++14 or with
the glibc update active in that repository.
Comment 1 Fabian Vogt 2016-02-12 13:28:24 UTC
It says

> error: macro "min" passed 3 arguments, but takes just 2

so somewhere there is a preprocessor macro called "min", which is defined before including sstream.
Comment 2 Arvin Schnell 2016-02-18 10:51:53 UTC
Only two include files already cause an error:

#include <btrfs/kerncompat.h>
#include <string>
Comment 3 Richard Biener 2016-02-18 11:10:59 UTC
(In reply to Arvin Schnell from comment #2)
> Only two include files already cause an error:
> 
> #include <btrfs/kerncompat.h>
> #include <string>

Well, you can't blame the kernel (C code) for #defining min/max.  If you need
to include C headers be prepared to #undef its macros.

Thus,

#include <btrfs/kerncompat.h>
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#include <string>

or include btrfs/kerncompat.h last (why do you need it at all...)

Kernel headers could of course also refrain from #defining min/max
(at least with __cplusplus being defined).

Still a snapper bug IMHO.
Comment 4 Arvin Schnell 2016-02-18 11:18:49 UTC
(In reply to Richard Biener from comment #3)
> Still a snapper bug IMHO.

No, snapper includes /usr/include/btrfs/send-utils.h which includes
btrfs/kerncompat.h. The header files from libbtrfs-devel are for general
use (the package was created for use from snapper).
Comment 5 Arvin Schnell 2016-03-04 14:12:32 UTC
Red Hat has proposed a patch for btrfs-progs:

https://patchwork.kernel.org/patch/8503881/
Comment 6 Richard Biener 2016-03-07 14:08:06 UTC
The following fix fixes the issue for me.  Please include that - snapper is the
only thing blocking images for GCC 6 build staging for me.

--- snapper/Btrfs.cc.orig       2016-03-07 15:02:40.766724314 +0100
+++ snapper/Btrfs.cc    2016-03-07 15:02:56.582906315 +0100
@@ -40,6 +40,8 @@
 #include <btrfs/send.h>
 #include <btrfs/send-stream.h>
 #include <btrfs/send-utils.h>
+#undef min
+#undef max
 #include <boost/version.hpp>
 #include <boost/thread.hpp>
 #endif
--- snapper/BtrfsUtils.cc.orig  2016-03-07 15:02:49.094820151 +0100
+++ snapper/BtrfsUtils.cc       2016-03-07 15:03:13.319098902 +0100
@@ -33,6 +33,8 @@
 #ifdef HAVE_LIBBTRFS
 #include <btrfs/ioctl.h>
 #include <btrfs/send-utils.h>
+#undef min
+#undef max
 #endif
 
 #include "snapper/Log.h"
Comment 7 David Sterba 2016-03-07 14:32:02 UTC
I've picked the linked patch upstream and will add it to btrfsprogs devel package, then snapper build will be fixed.
Comment 8 Bernhard Wiedemann 2016-03-07 15:00:10 UTC
This is an autogenerated message for OBS integration:
This bug (966257) was mentioned in
https://build.opensuse.org/request/show/367644 Factory / btrfsprogs
Comment 9 Swamp Workflow Management 2016-05-25 15:14:24 UTC
openSUSE-RU-2016:1398-1: An update that has 5 recommended fixes can now be installed.

Category: recommended (moderate)
Bug References: 888215,912170,956819,958562,966257
CVE References: 
Sources used:
openSUSE 13.2 (src):    btrfsprogs-4.5.3-13.1
Comment 10 Antoine Belvire 2016-07-29 18:31:48 UTC
Confirmed -> resolved fixed.