From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from forward101j.mail.yandex.net (forward101j.mail.yandex.net [IPv6:2a02:6b8:0:801:2::101]) by sourceware.org (Postfix) with ESMTPS id DE06C385DC14 for ; Mon, 18 May 2020 10:30:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DE06C385DC14 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gorlov.igorek@yandex.ru Received: from mxback1j.mail.yandex.net (mxback1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10a]) by forward101j.mail.yandex.net (Yandex) with ESMTP id 7BB8D1BE031D for ; Mon, 18 May 2020 13:30:22 +0300 (MSK) Received: from localhost (localhost [::1]) by mxback1j.mail.yandex.net (mxback/Yandex) with ESMTP id iwma52SJJH-UMLS6WKm; Mon, 18 May 2020 13:30:22 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1589797822; bh=9ZWdfhcb4RNGl/MzoD7ZDX14UYBEhyGS5vFFtEfMFJQ=; h=Message-Id:Date:Subject:To:From; b=BOifDUtTKxu4Lhur+1PfOMTn3KxDZ2PtgwJxhu1TvkBWJPqKuYZPGt6bbcpS0qBKI ejKsgLTRPd4wVPERn9ccgGw9BbXAFxUCEI1LpwpDDzIcZQzTp1PgJYsE+rPnKFTePn 7she4ZRCK6J4xmzjHqSVFGteU9jDn/BZevkITBF8= Authentication-Results: mxback1j.mail.yandex.net; dkim=pass header.i=@yandex.ru Received: by iva7-8a22bc446c12.qloud-c.yandex.net with HTTP; Mon, 18 May 2020 13:30:22 +0300 From: =?utf-8?B?0JjQs9C+0YDRjCDQk9C+0YDQu9C+0LI=?= Envelope-From: gorlov-igorek@yandex.ru To: gcc-help@gcc.gnu.org Subject: Invalid use of 'void' MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 18 May 2020 13:30:22 +0300 Message-Id: <12029271589797822@iva7-8a22bc446c12.qloud-c.yandex.net> Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 May 2020 10:30:28 -0000 Hi all. I have an issue when compiling a simple console program on Windows (Msys2). First, let's consider the program itself: void.cpp: #include #include #include int main() { // Getting any 2 valid void pointers void* p1=std::malloc(32); void* p2=std::malloc(64); if(p1==nullptr||p2==nullptr) { std::cout << "Error: failed to get 2 valid void pointers" << std::endl; return 1; } // Now trying to calculate the difference between these pointers std::ptrdiff_t difference=p2-p1; std::cout << "The difference is " << difference << std::endl; return 0; } This program is not compatible with the C++17 standard. However, we can compile it with -std=gnu++17 (C++17 with GNU extensions), because one of that extensions permits calculations on void pointers. Additionally, we append -Wno-pointer-arith to suppress the related warning. So, our command line looks like this: # g++ void.cpp -std=gnu++17 -Wno-pointer-arith -o void.exe GCC responds: void.cpp: In function 'int main()': void.cpp:16:30: error: invalid use of 'void'    16 | std::ptrdiff_t difference=p2-p1;       |                              ^~ What am I doing wrong?