This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/58325] New: Spurious unused-but-set-variable warning on delete[] of volatile pointer


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58325

            Bug ID: 58325
           Summary: Spurious unused-but-set-variable warning on delete[]
                    of volatile pointer
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cyp561 at gmail dot com

The following code should not generate âvolatile.cpp:3:16: warning: variable
âusedAndSetâ set but not used [-Wunused-but-set-variable]â, but does anyway:

{{{
int main()
{
    int *volatile setAndUsed = new int[1];
    delete[] setAndUsed;
}
}}}

The generated code looks correct, I assume _ZdaPv is the delete[]:

{{{
    .file    "volatile.cpp"
    .section    .text.startup,"ax",@progbits
    .p2align 4,,15
    .globl    main
    .type    main, @function
main:
.LFB0:
    .cfi_startproc
    subq    $24, %rsp
    .cfi_def_cfa_offset 32
    movl    $4, %edi
    call    _Znam
    movq    %rax, 8(%rsp)
    movq    8(%rsp), %rdi
    testq    %rdi, %rdi
    je    .L2
    call    _ZdaPv
.L2:
    xorl    %eax, %eax
    addq    $24, %rsp
    .cfi_def_cfa_offset 8
    ret
    .cfi_endproc
.LFE0:
    .size    main, .-main
    .ident    "GCC: (Gentoo 4.6.4 p1.0, pie-0.5.2) 4.6.4"
    .section    .note.GNU-stack,"",@progbits
}}}

Changing âdelete[]â to âdeleteâ or removing âvolatileâ removes the warning.
Adding â(void)setAndUsed;â squelches the warning.

Gives the warning: g++-4.6.4 g++-4.7.3
Does not give a warning: g++-3.4.6  g++-4.1.2  g++-4.2.4  g++-4.3.6  g++-4.4.7 
g++-4.5.4

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]