From c797ce13bd4298e087048c3f03883ab40e8a7dd0 Mon Sep 17 00:00:00 2001
From: Bin Meng <bmeng.cn@gmail.com>
Date: Wed, 6 Apr 2022 21:56:57 +0800
Subject: [PATCH 4/6] makefile: Specify -std=c++14 for mingw* builds

The windows executables fail to compile with gcc 11 mingw cross-compile
toolchain which defaults to '-std=c++17', due to conflicting definitions.

  In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/wtypes.h:8,
                   from /usr/x86_64-w64-mingw32/sys-root/mingw/include/winscard.h:10,
                   from /usr/x86_64-w64-mingw32/sys-root/mingw/include/windows.h:97,
                   from /usr/x86_64-w64-mingw32/sys-root/mingw/include/rpc.h:16,
                   from guid.h:23,
                   from parttypes.h:16,
                   from gptpart.h:22,
                   from gptpart.cc:27:
  /usr/x86_64-w64-mingw32/sys-root/mingw/include/rpcndr.h:64:11:
  error:reference to 'byte' is ambiguous
     64 |   typedef byte cs_byte;
        |           ^~~~
  In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/bits/stl_algobase.h:61,
                   from /usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/bits/char_traits.h:39,
                   from /usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/ios:40,
                   from /usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/ostream:38,
                   from /usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/iostream:39,
                   from gptpart.cc:26:
  /usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/bits/cpp_type_traits.h:404:30: note: candidates are: 'enum class std::byte'
    404 |   enum class byte : unsigned char;
        |                              ^~~~

The issue has been unnoticed so far all the way up to gcc 10, which
defaulted to '-std=c++14'. But it can still be reproduced with gcc 10
with an explicit '-std=c++17' flag.

"using namespace std" in header files is considered as a bad practice,
often known as global namespace pollution. Problems may occur when more
than one namespace has the same symbol name with signature, then it will
be ambiguous for the compiler to decide which one to use.

Let's explicitly specify -std=c++14 for mingw* builds.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---
 Makefile.mingw64 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.mingw64 b/Makefile.mingw64
index 3c63340..14b4b8c 100644
--- a/Makefile.mingw64
+++ b/Makefile.mingw64
@@ -2,7 +2,7 @@ CC=/usr/bin/x86_64-w64-mingw32-gcc
 CXX=/usr/bin/x86_64-w64-mingw32-g++
 STRIP=/usr/bin/x86_64-w64-mingw32-strip
 CFLAGS=-O2 -Wall -static -static-libgcc -static-libstdc++  -D_FILE_OFFSET_BITS=64 -g
-CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64
+CXXFLAGS=-O2 -Wall -std=c++14 -D_FILE_OFFSET_BITS=64
 #CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g
 LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows
 MBR_LIBS=support diskio diskio-windows basicmbr mbrpart
-- 
2.35.1

