0

I moved my MFC app to C++17 a while back and everything is great. I wanted to use std::to_chars so included in the cpp file. Didn't work. Tried to put it early in the StdAfx.h, same error(s).

Then I tried it with a console app and even if I add a boat load of headers used in the MFC app, I don't get the errors. The errors are some kind of header include conflicts, They come up just compiling StdAfx.h. It happens even if I make it the first file in StdAfx.h. I've alt-tabed between the properties of both projects and they are the same for all practical purposes.

UPDATE

I'm using: SDK 10.0 (latest installed version) Visual Studio 2019 (v142) Version 16.4.2 ISO C++17 Standard (std:c++17)

In the console app, I tried it both with and without pre-compiled headers and it works both ways. I've posted the complete error message with included in one cpp file.

I'm wondering if there is something lurking in my project file. It is 20 years old now brought up from VS6. For now I'll just use auto str(std::to_wstring(cur)); My next step is to create a clean project and copy my app source to that. Need to do try that anyway as it may fix this, I still can not add variables with the wizard.

The errors are while compiling <charconv>:

\charconv(1503,68): error C2672: 'std::_Max_value': no matching overloaded function found
\charconv(1912): message : see reference to function template instantiation 'std::errc std::_Convert_decimal_string_to_floating_type<_Floating>(const std::_Floating_point_string &,_FloatingType &,bool) noexcept' being compiled
1>        with
1>        [
1>            _Floating=float,
1>            _FloatingType=float
1>        ]
\charconv(2053): message : see reference to function template instantiation 'std::from_chars_result std::_Ordinary_floating_from_chars<_Floating>(const char *const ,const char *const ,_Floating &,const std::chars_format,const bool,const char *) noexcept' being compiled
1>        with
1>        [
1>            _Floating=float
1>        ]
\charconv(2065): message : see reference to function template instantiation 'std::from_chars_result std::_Floating_from_chars<float>(const char *const ,const char *const ,_Floating &,const std::chars_format) noexcept' being compiled
1>        with
1>        [
1>            _Floating=float
1>        ]
\charconv(1503,1): error C2782: 'const _Ty &std::_Max_value(const _Ty &,const _Ty &) noexcept(<expr>)': template parameter '_Ty' is ambiguous
\utility(35): message : see declaration of 'std::_Max_value'
\charconv(1503,1): message : could be 'int32_t'
\charconv(1503,1): message : or       'int'
\charconv(1503,1): error C2784: 'const _Ty &std::_Max_value(const _Ty &,const _Ty &) noexcept(<expr>)': could not deduce template argument for 'const _Ty &' from 'const int32_t'
\utility(35): message : see declaration of 'std::_Max_value'
\charconv(1503,44): error C2789: '_Positive_exponent': an object of const-qualified type must be initialized
\charconv(1503): message : see declaration of '_Positive_exponent'

The headers I added to the console app without creating the issue:

#include <boost/date_time/gregorian/greg_date.hpp>
#include <boost/locale.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/spirit/home/x3.hpp>
#include <SDKDDKVer.h>
#include <intsafe.h>
#include <afxwin.h>         // MFC core and standard components
#include <charconv>
#include <afxrich.h>        // MFC Rich Edit Control used in most.
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
#include <afxdb.h>          // ODBC support
#include <afxdtctl.h>       // MFC support for Internet Explorer 4 Common Controls
#include <afxcmn.h>         // MFC support for Windows Common Controls
#include <afxcview.h>       // MFC Common controls
#include <afxdhtml.h>       // html support
#include <afxdlgs.h>        // Common Dialogs
#include <afxtempl.h>       // MFC template support.
#include <atlimage.h>       // GDIPlus, not....
#include <raserror.h>       // ERROR_ defines
#include <direct.h>         // for _tchdir( GetProjectDirectory( ) );
#include <shlobj.h>         // SHGetFolderPath(...)
#include <afxdialogex.h>    //for ReTreeDlg
#include <gdiplus.h>        // GDIPlus
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
#include <boost/asio/connect.hpp>
#include <boost/bind.hpp>
#include <boost/exception/exception.hpp>
#include <boost/thread.hpp>
#include <boost/variant.hpp>
#include <boost/lexical_cast.hpp>

Nine times out of ten I'll figure it out while writing my question. This is a one time and I'm at a loss. Just hoping someone has seen the likes of this before.

lakeweb
  • 1,859
  • 2
  • 16
  • 21
  • Which Visual Studio version are you using and which standard are you compiling with? – Nicol Bolas Dec 20 '19 at 18:00
  • Does it work if you build *without* pre-compiled headers? That is *don't* use `StdAfx.h` at all/anywhere. – Jesper Juhl Dec 20 '19 at 18:08
  • In the console app, I tried it both with and without pre-compiled headers and it works. I'm using the latest VS2019 latest `10` sdk and of course c++17 as the language. I'm one update behind, I'll fetch that next, but I doubt it will change this. I'd update in the body but now google won't let me log in with firefox..... – lakeweb Dec 20 '19 at 19:47
  • 1
    Please show the full error message. With templates it's important to understand, what the compiler tried to do. The truncated error message only shows, where the compiler ultimately gave up. For readability you could strip the common path prefix. – IInspectable Dec 21 '19 at 10:22
  • I can’t always use the classwizard on my projects anymore. – Andrew Truckle Dec 22 '19 at 05:54
  • 1
    hi @Andrew Truckle Over the last couple of weeks, I've moved my project to unicode. I started with a fresh empty project and copied files over. Now the wizard works. The difference I can see is `` in the old project but does not exist in the new one. I did have to add the other resources by hand as VS won't let you drop them in anymore. – lakeweb Jan 04 '20 at 14:50

1 Answers1

0

This was completely my doing. Turns out, in one of my additional include paths, I had an old stdint.h. The compiler would pick that one up before finding the newer one in the SDK. It was right enough for everything to work until I tried to incorporate charconv. It was dated 2012, I had put it there as part of the move to VS2010.

So the lesson is, if there is a strange conflict like this, be sure to check if you have done something stupid, like put a file in your own includes that should never have been put there. Doing so may fix something today, but may break something years down the line.

lakeweb
  • 1,859
  • 2
  • 16
  • 21