Bug 63391

Summary: Erroneous -Wsign-conversion with offsetof
Product: gcc Reporter: Ian Mallett <ian>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: minor CC: daniel.kruegler, webrown.cpp
Priority: P3 Keywords: diagnostic
Version: 4.8.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Ian Mallett 2014-09-27 18:53:45 UTC
//Bug report:
//	by Ian Mallett
//	Compile with "g++ <name.cpp> -std=c++11 -Wsign-conversion

#include <cstdint>
#include <cstddef>


struct Foo {
	char data;
};


int main(int /*argc*/, char* /*argv*/[]) {
	int num = 6;
	#if 0 //No warning
		size_t offset = offsetof(struct Foo,data);
		delete [] new char[offset*static_cast<size_t>(num)];
	#else //warning
		delete [] new char[offsetof(struct Foo,data)*static_cast<size_t>(num)];
	#endif

	return 0;
}
Comment 1 Marek Polacek 2019-08-08 16:19:05 UTC
Fixed now by r274211.