Author Topic: warning C4146: unary minus operator applied to unsigned type warnings in v1.0  (Read 22299 times)

JohnWS

  • Newbie
  • *
  • Posts: 6
    • View Profile
Hi

I'm using Microsoft Visual C++ 2008 Express Edition SP1, with just::thread C++ Thread Library v1.0 to compile as the basic sample program below:

// ThreadTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <thread>
#include <mutex>
#include <iostream>

std::mutex io_mutex;

void greeting(const char* message) {
    std::lock_guard<std::mutex> lk(io_mutex);
    std::cout << message << std::endl;
}

int _tmain(int argc, _TCHAR* argv[]) {
    std::thread t(greeting,"Hello from another thread");
    greeting("Hello from the main thread");
    t.join();
    return 0;
}

The compilation succeeds but I get the following warnings:

1>------ Rebuild All started: Project: ThreadTest, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'ThreadTest', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>ThreadTest.cpp
1>c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(109) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(108) : while compiling class template member function 'unsigned int std::__atomic_integral<__itype>::fetch_sub(__itype,std::memory_order) volatile'
1>        with
1>        [
1>            __itype=unsigned int
1>        ]
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(446) : see reference to class template instantiation 'std::__atomic_integral<__itype>' being compiled
1>        with
1>        [
1>            __itype=unsigned int
1>        ]
1>c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(109) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(108) : while compiling class template member function 'unsigned long std::__atomic_integral<__itype>::fetch_sub(__itype,std::memory_order) volatile'
1>        with
1>        [
1>            __itype=unsigned long
1>        ]
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(486) : see reference to class template instantiation 'std::__atomic_integral<__itype>' being compiled
1>        with
1>        [
1>            __itype=unsigned long
1>        ]
1>c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(109) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(108) : while compiling class template member function '__jss::uintmax_t std::__atomic_integral<__itype>::fetch_sub(__itype,std::memory_order) volatile'
1>        with
1>        [
1>            __itype=__jss::uintmax_t
1>        ]
1>        c:\program files\justsoftwaresolutions\justthread\include\cstdatomic(506) : see reference to class template instantiation 'std::__atomic_integral<__itype>' being compiled
1>        with
1>        [
1>            __itype=__jss::uintmax_t
1>        ]
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>LINK : C:\ThreadTest\Debug\ThreadTest.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Build log was saved at "file://c:\ThreadTest\ThreadTest\Debug\BuildLog.htm"
1>ThreadTest - 0 error(s), 3 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========


I think Kenneth reported these warnings (amongst other errors) in v0.3 of the library but I've not seen anything else since, which probably means that it's a school-boy error on my part. It doesn't appear to break anything (at least as far as I can tell from simple applications), but does anyone know how to get rid of these warnings?

John

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Hi John,

You're not doing anything wrong; these warnings are superfluous and warn about valid code in this instance. You can disable the specific warning by adding

#pragma warning(disable:4146)

to your stdafx.h file. I'll fix it for the next build.

Anthony

JohnWS

  • Newbie
  • *
  • Posts: 6
    • View Profile
Okay. That's good to know.

Thanks Anthony.

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
The latest version should generate far fewer warnings.