[CDRIVER-969] declaration of 'index' shadows a global declaration Created: 28/Oct/15  Updated: 18/Nov/15  Resolved: 30/Oct/15

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.2.0
Fix Version/s: 1.3.0-beta0

Type: Bug Priority: Major - P3
Reporter: Hannes Magnusson Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

[2015/10/28 11:39:21.134] src/mongoc/mongoc-write-command.c: In function 'too_large_error':
[2015/10/28 11:39:21.134] src/mongoc/mongoc-write-command.c:360:32: error: declaration of 'index' shadows a global declaration [-Werror=shadow]
[2015/10/28 11:39:21.135] src/mongoc/mongoc-write-command.c: In function '_mongoc_write_command_insert_legacy':



 Comments   
Comment by Githook User [ 30/Oct/15 ]

Author:

{u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}

Message: CDRIVER-969: declaration of 'index' shadows a global declaration

This only happens on certain GCC versions before 4.8, and is a bug
in the compiler, but unfortunately evergreen is running that version
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/d45bd957076acbf497e22c53805b3a8f6c96b6d3

Comment by A. Jesse Jiryu Davis [ 28/Oct/15 ]

This was fixed in GCC 4.8 "The option -Wshadow no longer warns if a declaration shadows a function declaration, unless the former declares a function or pointer to function":

https://gcc.gnu.org/gcc-4.8/changes.html

A complaint about a variable named "index" is exactly the valid real-world use case they cite as justification for the fix.

I guess we're using a pretty old GCC some places.

Comment by Hannes Magnusson [ 28/Oct/15 ]

This appears to happen only on certain version of gcc, and likely caused by :

$ grep index /usr/include/string.h
extern char *index (char *__s, int __c)

Generated at Wed Feb 07 21:11:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.