cbeck88 / strict-variant

A realtime/embedded-friendly C++11 variant type which is never empty and prevents undesirable implicit conversions
Boost Software License 1.0
98 stars 12 forks source link

C4348 redefinition of default parameter (variant.hpp:183) #1

Closed NiklasRosenstein closed 7 years ago

NiklasRosenstein commented 7 years ago

Hi! I'm getting this warning with MSVC 2015 (19.00.23918)

craftr.lib.strict-variant-1.0.0\data/strict-variant-0.3\include\strict_variant/variant.hpp(183): warning C4348: 'strict_variant::variant<int,std::string>::initializer': redefinition of default parameter: parameter 2
craftr.lib.strict-variant-1.0.0\data/strict-variant-0.3\include\strict_variant/variant.hpp(188): note: see declaration of 'strict_variant::variant<int,std::string>::initializer'
C:\Users\niklas\repos\craftr\craftr\examples\examples.cpp\main.cpp(113): note: see reference to class template instantiation 'strict_variant::variant<int,std::string>' being compiled

I'm not sure how to fix it, otherwise I'd make a PR 😊

cbeck88 commented 7 years ago

Hi, I get this warning also on appveyor.

I'm not sure what it's about, but I might look into it soon. I generally develop on gcc and clang, I didn't put much effort into msvc warnings so far.

There's some template partial specialization going on here that also involves parameter packs and non-type template parameters, it might that if I make it a little less tricky then MSVC won't complain. There was something else I wanted to tweak about how the default constructor is declared anyways -- it's not clear to me if MSVC is complaining about the initializer itself or some particular instantiation of it.

cbeck88 commented 7 years ago

Hi, I made a few minor fixups and twiddled the "intiializer" class so that it doesn't use default template parameters. It looks like it's fixed on appveyor, but please check current master please and let me know if it's fixed for you also.

I'm getting a different warning on appveyor now:

C:\projects\strict_variant\include\strict_variant/recursive_wrapper.hpp(82): warning C4521: 'strict_variant::recursive_wrapper<std::string>': multiple copy constructors specified

I'm going to take a look at that shortly.

cbeck88 commented 7 years ago

@NiklasRosenstein : According to what I read online, the multiple copy constructors warning is just informational and doesn't indicate a bug. http://stackoverflow.com/questions/24264191/compiler-warning-for-multiple-copy-constructors

I went through the appveyor log in more detail, as far as I can tell the other warnings are similar, or, represent warnings about implicit conversions in the test code. Let me know if you see any warnings that you think are a problem.

NiklasRosenstein commented 7 years ago

In just this simple test, I no longer get any warning, even with /W4.

#include <strict_variant/variant.hpp>
#include <iostream>
#include <string>

int main() {
  strict_variant::variant<int, std::string> val = "foo";
  std::cout << *val.get<std::string>() << "\n";
  return 0;
}

Good job :)