From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id A61923858D20 for ; Fri, 4 Feb 2022 12:13:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A61923858D20 Received: by mail-wr1-x430.google.com with SMTP id m14so10880721wrg.12 for ; Fri, 04 Feb 2022 04:13:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vF+iZ70/VmkFIp0xTDULJSCZAu5XeCggOkhLUci8qms=; b=7mcm3cFtWB8ZevQ6hrhbnlKc7uizlNf/7AsPqmJYMSWMb9qDH3xN2nlySPeiTtZJxz aUYEHuhpQQOLh/noAXU3quUmax3IU4l7HDb2umBfM3fV9uMF1Wzp6qL2IJR9IDd6ZXAC z0Y5UKY9cP2HutHUWGlwzptjFjrGLeyI74PwkbmaoLUB4+oZt/LT+dPxyjQVok61iyQk Exh5W1/IKXGRS4/pdG4+WkhyWkPlOTSf41709ta6+6fxRYtIDVIj9mHnbDJYhyCYAJDU 3dl/QL+lTciIT0ARPgt2MOxp9uhq8Ayq7jO1X0VlbLg0mlv8WwP2lXRN3icVL3qCrmcR vB/w== X-Gm-Message-State: AOAM532XLZ2/SG48YcB6HOPyTzT5WwJqn83c+9MDR267Fc0S6tLVMHmB 5vToMuM8se7N/3nRkr6DXEFCghif8sR2PN3xyVA= X-Google-Smtp-Source: ABdhPJwMr6HmfesHpiwm17pKt+DzlY3iJYcTO3+rFwFfarcH+wI5HttkcTBJPRQvihLBfYywIbbccwCTflgy+0fUS28= X-Received: by 2002:adf:fe12:: with SMTP id n18mr1204218wrr.395.1643976835578; Fri, 04 Feb 2022 04:13:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 4 Feb 2022 12:13:44 +0000 Message-ID: Subject: Re: Doubts regarding the issue (bug 62181) To: Krishna Narayanan Cc: gcc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Fri, 04 Feb 2022 12:13:59 -0000 On Fri, 4 Feb 2022 at 11:36, Krishna Narayanan via Gcc-help wrote: > > Respected sir, > I went through the compiler flags and mistake was on my side using the 'w' > suppressor flag to remove the warnings without knowing it.Thanks for the > docs and reply. > > By unicode I meant there is a question mark inside a diagonal.(unicode > error symbol) That means it's printing garbage characters that can't be processed as valid UTF-8, so explicitly NOT unicode. Calling that unicode is very confusing. > Sir this is perspective with the third print that is > "cc"+foobar() where I get zR for gcc (9.3.0) and unicode for g++-10.1. > I got your point regarding the garbage value and to throw a warning is > better than to get such an unwanted output. > > I thought there would be a specific reason why it had come because in const > char *a ="aa"+'operator/number' i.e when I add some character with some > change it gives blank space for numbers and operators, where as for > addition of 'a' in *a= "aa"+'a' it give 4 times the unicode symbol but for > *c="cc" +'c' and *b="bb"+'b' gives a space as output.Yes it has been quite > unpredictable and undefined behaviour. The nature of undefined behaviour is to be unpredictable. Compile with -fsanitize=address to get a lot more detail about what your buggy code is doing. You'll see an explanation of where the pointer arithmetic goes, and what's in memory there. > > So has the request of warning been granted in the upcoming gcc version!? Do you get any warning when compiling your buggy example with gcc? I don't. However, when I compile it with clang I get: oflow.c:10:23: warning: adding 'char' to a string does not append to the string [-Wstring-plus-int] const char *b = "bb" + bar(); ~~~~~^~~~~~~ oflow.c:10:23: note: use array indexing to silence this warning const char *b = "bb" + bar(); ^ & [ ] oflow.c:11:22: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] const char *c = "cc" + foobar(); ~~~~~^~~~~~~~~~ oflow.c:11:22: note: use array indexing to silence this warning const char *c = "cc" + foobar(); ^ & [ ] 2 warnings generated.